mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-21 16:38:37 -06:00
First version of functional tests working
This commit is contained in:
parent
e282521040
commit
c2feffa50c
@ -69,7 +69,10 @@
|
||||
"psr-4": {
|
||||
"ShlinkioTest\\Shlink\\CLI\\": "module/CLI/test",
|
||||
"ShlinkioTest\\Shlink\\Rest\\": "module/Rest/test",
|
||||
"ShlinkioTest\\Shlink\\Core\\": "module/Core/test",
|
||||
"ShlinkioTest\\Shlink\\Core\\": [
|
||||
"module/Core/test",
|
||||
"module/Core/test-func"
|
||||
],
|
||||
"ShlinkioTest\\Shlink\\Common\\": [
|
||||
"module/Common/test",
|
||||
"module/Common/test-func"
|
||||
@ -85,7 +88,8 @@
|
||||
"cs-fix": "phpcbf",
|
||||
"serve": "php -S 0.0.0.0:8000 -t public/",
|
||||
"test": "phpunit --coverage-clover build/clover.xml",
|
||||
"pretty-test": "phpunit --coverage-html build/coverage"
|
||||
"pretty-test": "phpunit --coverage-html build/coverage",
|
||||
"func-test": "phpunit -c phpunit-func.xml"
|
||||
},
|
||||
"config": {
|
||||
"process-timeout": 0,
|
||||
|
@ -4,9 +4,31 @@ declare(strict_types=1);
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\Tools\Console\ConsoleRunner;
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
|
||||
/** @var ContainerInterface $container */
|
||||
$isTest = false;
|
||||
foreach ($_SERVER['argv'] as $i => $arg) {
|
||||
if ($arg === '--test') {
|
||||
unset($_SERVER['argv'][$i]);
|
||||
$isTest = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** @var ContainerInterface|ServiceManager $container */
|
||||
$container = include __DIR__ . '/container.php';
|
||||
|
||||
// If in testing env, override DB connection to use an in-memory sqlite database
|
||||
if ($isTest) {
|
||||
$container->setAllowOverride(true);
|
||||
$config = $container->get('config');
|
||||
$config['entity_manager']['connection'] = [
|
||||
'driver' => 'pdo_sqlite',
|
||||
'memory' => true,
|
||||
];
|
||||
$container->setService('config', $config);
|
||||
}
|
||||
|
||||
/** @var EntityManager $em */
|
||||
$em = $container->get(EntityManager::class);
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use ShlinkioTest\Shlink\Common\DbUnit\DatabaseTestCase;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
@ -13,17 +12,10 @@ if (! file_exists('.env')) {
|
||||
|
||||
/** @var ServiceManager $sm */
|
||||
$sm = require __DIR__ . '/config/container.php';
|
||||
$sm->setAllowOverride(true);
|
||||
$config = $sm->get('config');
|
||||
$config['entity_manager']['connection'] = [
|
||||
'driver' => 'pdo_sqlite',
|
||||
'memory' => true,
|
||||
];
|
||||
$sm->setService('config', $config);
|
||||
|
||||
$process = new Process('vendor/bin/doctrine-migrations migrations:migrate --no-interaction -q', __DIR__);
|
||||
// Create database
|
||||
$process = new Process('vendor/bin/doctrine orm:schema-tool:create --no-interaction -q --test', __DIR__);
|
||||
$process->inheritEnvironmentVariables()
|
||||
->setTimeout(60 * 5) // 5 minutes
|
||||
->mustRun();
|
||||
|
||||
DatabaseTestCase::$em = $sm->get(EntityManagerInterface::class);
|
||||
DatabaseTestCase::$em = $sm->get('em');
|
||||
|
49
module/Core/test-func/Repository/TagRepositoryTest.php
Normal file
49
module/Core/test-func/Repository/TagRepositoryTest.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\Repository;
|
||||
|
||||
use Shlinkio\Shlink\Core\Entity\Tag;
|
||||
use Shlinkio\Shlink\Core\Repository\TagRepository;
|
||||
use ShlinkioTest\Shlink\Common\DbUnit\DatabaseTestCase;
|
||||
|
||||
class TagRepositoryTest extends DatabaseTestCase
|
||||
{
|
||||
const ENTITIES_TO_EMPTY = [
|
||||
Tag::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var TagRepository
|
||||
*/
|
||||
private $repo;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->repo = $this->getEntityManager()->getRepository(Tag::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function deleteByNameDoesNothingWhenEmptyListIsProvided()
|
||||
{
|
||||
$this->assertEquals(0, $this->repo->deleteByName([]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function allTagsWhichMatchNameAreDeleted()
|
||||
{
|
||||
$names = ['foo', 'bar', 'baz'];
|
||||
$toDelete = ['foo', 'baz'];
|
||||
|
||||
foreach ($names as $name) {
|
||||
$this->getEntityManager()->persist(new Tag($name));
|
||||
}
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$this->assertEquals(2, $this->repo->deleteByName($toDelete));
|
||||
}
|
||||
}
|
15
phpunit-func.xml
Normal file
15
phpunit-func.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<phpunit bootstrap="./func_tests_bootstrap.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Shlink functional database tests">
|
||||
<directory>./module/*/test-func</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">./module/*/src/Repository</directory>
|
||||
<directory suffix=".php">./module/*/src/**/Repository</directory>
|
||||
<directory suffix=".php">./module/*/src/**/**/Repository</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
Loading…
Reference in New Issue
Block a user