2019-01-27 14:14:18 +03:00
|
|
|
<?php
|
2019-10-05 18:26:10 +03:00
|
|
|
|
2019-01-27 14:14:18 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioApiTest\Shlink\Rest\Fixtures;
|
|
|
|
|
2021-02-10 01:56:46 +03:00
|
|
|
use Cake\Chronos\Chronos;
|
2019-01-27 14:14:18 +03:00
|
|
|
use Doctrine\Common\DataFixtures\AbstractFixture;
|
|
|
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
2019-12-16 23:46:27 +03:00
|
|
|
use Doctrine\Persistence\ObjectManager;
|
2021-02-10 01:56:46 +03:00
|
|
|
use ReflectionObject;
|
2019-01-27 14:14:18 +03:00
|
|
|
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
|
|
|
use Shlinkio\Shlink\Core\Entity\Visit;
|
2022-09-23 19:05:17 +03:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Model\Visitor;
|
2019-01-27 14:14:18 +03:00
|
|
|
|
|
|
|
class VisitsFixture extends AbstractFixture implements DependentFixtureInterface
|
|
|
|
{
|
|
|
|
public function getDependencies(): array
|
|
|
|
{
|
|
|
|
return [ShortUrlsFixture::class];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function load(ObjectManager $manager): void
|
|
|
|
{
|
|
|
|
/** @var ShortUrl $abcShortUrl */
|
|
|
|
$abcShortUrl = $this->getReference('abc123_short_url');
|
2021-02-07 23:31:12 +03:00
|
|
|
$manager->persist(
|
|
|
|
Visit::forValidShortUrl($abcShortUrl, new Visitor('shlink-tests-agent', '', '44.55.66.77', '')),
|
|
|
|
);
|
|
|
|
$manager->persist(Visit::forValidShortUrl(
|
|
|
|
$abcShortUrl,
|
|
|
|
new Visitor('shlink-tests-agent', 'https://google.com', '4.5.6.7', ''),
|
|
|
|
));
|
|
|
|
$manager->persist(Visit::forValidShortUrl($abcShortUrl, new Visitor('shlink-tests-agent', '', '1.2.3.4', '')));
|
2019-01-27 14:14:18 +03:00
|
|
|
|
|
|
|
/** @var ShortUrl $defShortUrl */
|
|
|
|
$defShortUrl = $this->getReference('def456_short_url');
|
2021-02-07 23:31:12 +03:00
|
|
|
$manager->persist(
|
2021-05-22 22:05:54 +03:00
|
|
|
Visit::forValidShortUrl($defShortUrl, new Visitor('cf-facebook', '', '127.0.0.1', '')),
|
2021-02-07 23:31:12 +03:00
|
|
|
);
|
|
|
|
$manager->persist(
|
|
|
|
Visit::forValidShortUrl($defShortUrl, new Visitor('shlink-tests-agent', 'https://app.shlink.io', '', '')),
|
|
|
|
);
|
2019-01-27 14:14:18 +03:00
|
|
|
|
2021-01-05 21:29:42 +03:00
|
|
|
/** @var ShortUrl $ghiShortUrl */
|
|
|
|
$ghiShortUrl = $this->getReference('ghi789_short_url');
|
2021-02-07 23:31:12 +03:00
|
|
|
$manager->persist(Visit::forValidShortUrl($ghiShortUrl, new Visitor('shlink-tests-agent', '', '1.2.3.4', '')));
|
|
|
|
$manager->persist(
|
|
|
|
Visit::forValidShortUrl($ghiShortUrl, new Visitor('shlink-tests-agent', 'https://app.shlink.io', '', '')),
|
|
|
|
);
|
2020-02-02 12:46:38 +03:00
|
|
|
|
2021-02-10 01:56:46 +03:00
|
|
|
$manager->persist($this->setVisitDate(
|
|
|
|
Visit::forBasePath(new Visitor('shlink-tests-agent', 'https://doma.in', '1.2.3.4', '')),
|
|
|
|
'2020-01-01',
|
|
|
|
));
|
|
|
|
$manager->persist($this->setVisitDate(
|
2021-02-09 00:44:58 +03:00
|
|
|
Visit::forRegularNotFound(new Visitor('shlink-tests-agent', 'https://doma.in/foo/bar', '1.2.3.4', '')),
|
2021-02-10 01:56:46 +03:00
|
|
|
'2020-02-01',
|
|
|
|
));
|
|
|
|
$manager->persist($this->setVisitDate(
|
2021-05-22 16:09:14 +03:00
|
|
|
Visit::forInvalidShortUrl(new Visitor('cf-facebook', 'https://doma.in/foo', '1.2.3.4', 'foo.com')),
|
2021-02-10 01:56:46 +03:00
|
|
|
'2020-03-01',
|
|
|
|
));
|
2021-02-09 00:44:58 +03:00
|
|
|
|
2019-01-27 14:14:18 +03:00
|
|
|
$manager->flush();
|
|
|
|
}
|
2021-02-10 01:56:46 +03:00
|
|
|
|
|
|
|
private function setVisitDate(Visit $visit, string $date): Visit
|
|
|
|
{
|
|
|
|
$ref = new ReflectionObject($visit);
|
|
|
|
$dateProp = $ref->getProperty('date');
|
|
|
|
$dateProp->setAccessible(true);
|
|
|
|
$dateProp->setValue($visit, Chronos::parse($date));
|
|
|
|
|
|
|
|
return $visit;
|
|
|
|
}
|
2019-01-27 14:14:18 +03:00
|
|
|
}
|