-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #476 from acelaya-forks/feature/fix-log-fields-error
Feature/fix log fields error
- Loading branch information
Showing
9 changed files
with
124 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ShlinkMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Column; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\DBAL\Schema\SchemaException; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20190824075137 extends AbstractMigration | ||
{ | ||
/** | ||
* @throws SchemaException | ||
*/ | ||
public function up(Schema $schema): void | ||
{ | ||
$this->getRefererColumn($schema)->setLength(1024); | ||
} | ||
|
||
/** | ||
* @throws SchemaException | ||
*/ | ||
public function down(Schema $schema): void | ||
{ | ||
$this->getRefererColumn($schema)->setLength(256); | ||
} | ||
|
||
/** | ||
* @throws SchemaException | ||
*/ | ||
private function getRefererColumn(Schema $schema): Column | ||
{ | ||
return $schema->getTable('visits')->getColumn('referer'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ShlinkioTest\Shlink\Core\Model; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Shlinkio\Shlink\Common\Util\StringUtilsTrait; | ||
use Shlinkio\Shlink\Core\Model\Visitor; | ||
|
||
use function str_repeat; | ||
use function substr; | ||
|
||
class VisitorTest extends TestCase | ||
{ | ||
use StringUtilsTrait; | ||
|
||
/** | ||
* @test | ||
* @dataProvider provideParams | ||
*/ | ||
public function providedFieldsValuesAreCropped(array $params, array $expected): void | ||
{ | ||
$visitor = new Visitor(...$params); | ||
['userAgent' => $userAgent, 'referer' => $referer, 'remoteAddress' => $remoteAddress] = $expected; | ||
|
||
$this->assertEquals($userAgent, $visitor->getUserAgent()); | ||
$this->assertEquals($referer, $visitor->getReferer()); | ||
$this->assertEquals($remoteAddress, $visitor->getRemoteAddress()); | ||
} | ||
|
||
public function provideParams(): iterable | ||
{ | ||
yield 'all values are bigger' => [ | ||
[str_repeat('a', 1000), str_repeat('b', 2000), str_repeat('c', 500)], | ||
[ | ||
'userAgent' => str_repeat('a', Visitor::USER_AGENT_MAX_LENGTH), | ||
'referer' => str_repeat('b', Visitor::REFERER_MAX_LENGTH), | ||
'remoteAddress' => str_repeat('c', Visitor::REMOTE_ADDRESS_MAX_LENGTH), | ||
], | ||
]; | ||
yield 'some values are smaller' => [ | ||
[str_repeat('a', 10), str_repeat('b', 2000), null], | ||
[ | ||
'userAgent' => str_repeat('a', 10), | ||
'referer' => str_repeat('b', Visitor::REFERER_MAX_LENGTH), | ||
'remoteAddress' => null, | ||
], | ||
]; | ||
yield 'random strings' => [ | ||
[ | ||
$userAgent = $this->generateRandomString(2000), | ||
$referer = $this->generateRandomString(50), | ||
null, | ||
], | ||
[ | ||
'userAgent' => substr($userAgent, 0, Visitor::USER_AGENT_MAX_LENGTH), | ||
'referer' => $referer, | ||
'remoteAddress' => null, | ||
], | ||
]; | ||
} | ||
} |