1
0
mirror of synced 2025-02-09 00:39:25 +03:00

Format commands' tests

To simplify and organise the code (also replacing `$this->assert*`
with `self::assert*`).
This commit is contained in:
Luís Cobucci 2017-11-24 01:13:52 +01:00
parent 8a893068ce
commit 43a88d539d
No known key found for this signature in database
GPG Key ID: EC61C5F01750ED3C
7 changed files with 165 additions and 179 deletions

View File

@ -30,15 +30,10 @@ class ClearCacheCollectionRegionCommandTest extends OrmFunctionalTestCase
$this->enableSecondLevelCache();
parent::setUp();
$this->application = new Application();
$this->command = new CollectionRegionCommand();
$this->application->setHelperSet(new HelperSet(
[
'em' => new EntityManagerHelper($this->_em)
]
));
$this->application = new Application();
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)]));
$this->application->add($this->command);
}
@ -46,11 +41,13 @@ class ClearCacheCollectionRegionCommandTest extends OrmFunctionalTestCase
{
$command = $this->application->find('orm:clear-cache:region:collection');
$tester = new CommandTester($command);
$tester->execute(
[
'command' => $command->getName(),
'--all' => true,
], ['decorated' => false]
],
['decorated' => false]
);
$this->assertEquals('Clearing all second-level cache collection regions' . PHP_EOL, $tester->getDisplay());
@ -60,12 +57,14 @@ class ClearCacheCollectionRegionCommandTest extends OrmFunctionalTestCase
{
$command = $this->application->find('orm:clear-cache:region:collection');
$tester = new CommandTester($command);
$tester->execute(
[
'command' => $command->getName(),
'owner-class' => State::class,
'association' => 'cities',
], ['decorated' => false]
],
['decorated' => false]
);
$this->assertEquals('Clearing second-level cache for collection "Doctrine\Tests\Models\Cache\State#cities"' . PHP_EOL, $tester->getDisplay());
@ -75,13 +74,15 @@ class ClearCacheCollectionRegionCommandTest extends OrmFunctionalTestCase
{
$command = $this->application->find('orm:clear-cache:region:collection');
$tester = new CommandTester($command);
$tester->execute(
[
'command' => $command->getName(),
'owner-class' => State::class,
'association' => 'cities',
'owner-id' => 1,
], ['decorated' => false]
],
['decorated' => false]
);
$this->assertEquals('Clearing second-level cache entry for collection "Doctrine\Tests\Models\Cache\State#cities" owner entity identified by "1"' . PHP_EOL, $tester->getDisplay());
@ -91,13 +92,15 @@ class ClearCacheCollectionRegionCommandTest extends OrmFunctionalTestCase
{
$command = $this->application->find('orm:clear-cache:region:collection');
$tester = new CommandTester($command);
$tester->execute(
[
'command' => $command->getName(),
'owner-class' => State::class,
'association' => 'cities',
'--flush' => true,
], ['decorated' => false]
],
['decorated' => false]
);
$this->assertEquals('Flushing cache provider configured for "Doctrine\Tests\Models\Cache\State#cities"' . PHP_EOL, $tester->getDisplay());

View File

@ -30,15 +30,10 @@ class ClearCacheEntityRegionCommandTest extends OrmFunctionalTestCase
$this->enableSecondLevelCache();
parent::setUp();
$this->application = new Application();
$this->command = new EntityRegionCommand();
$this->application->setHelperSet(new HelperSet(
[
'em' => new EntityManagerHelper($this->_em)
]
));
$this->application = new Application();
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)]));
$this->application->add($this->command);
}
@ -46,11 +41,13 @@ class ClearCacheEntityRegionCommandTest extends OrmFunctionalTestCase
{
$command = $this->application->find('orm:clear-cache:region:entity');
$tester = new CommandTester($command);
$tester->execute(
[
'command' => $command->getName(),
'--all' => true,
], ['decorated' => false]
],
['decorated' => false]
);
$this->assertEquals('Clearing all second-level cache entity regions' . PHP_EOL, $tester->getDisplay());
@ -60,11 +57,13 @@ class ClearCacheEntityRegionCommandTest extends OrmFunctionalTestCase
{
$command = $this->application->find('orm:clear-cache:region:entity');
$tester = new CommandTester($command);
$tester->execute(
[
'command' => $command->getName(),
'entity-class' => Country::class,
], ['decorated' => false]
],
['decorated' => false]
);
$this->assertEquals('Clearing second-level cache for entity "Doctrine\Tests\Models\Cache\Country"' . PHP_EOL, $tester->getDisplay());
@ -74,12 +73,14 @@ class ClearCacheEntityRegionCommandTest extends OrmFunctionalTestCase
{
$command = $this->application->find('orm:clear-cache:region:entity');
$tester = new CommandTester($command);
$tester->execute(
[
'command' => $command->getName(),
'entity-class' => Country::class,
'entity-id' => 1,
], ['decorated' => false]
],
['decorated' => false]
);
$this->assertEquals('Clearing second-level cache entry for entity "Doctrine\Tests\Models\Cache\Country" identified by "1"' . PHP_EOL, $tester->getDisplay());
@ -89,12 +90,14 @@ class ClearCacheEntityRegionCommandTest extends OrmFunctionalTestCase
{
$command = $this->application->find('orm:clear-cache:region:entity');
$tester = new CommandTester($command);
$tester->execute(
[
'command' => $command->getName(),
'entity-class' => Country::class,
'--flush' => true,
], ['decorated' => false]
],
['decorated' => false]
);
$this->assertEquals('Flushing cache provider configured for entity named "Doctrine\Tests\Models\Cache\Country"' . PHP_EOL, $tester->getDisplay());

View File

@ -4,10 +4,10 @@ namespace Doctrine\Tests\ORM\Tools\Console\Command;
use Doctrine\ORM\Tools\Console\Command\ClearCache\QueryRegionCommand;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Application;
use Doctrine\Tests\OrmFunctionalTestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Tester\CommandTester;
/**
* @group DDC-2183
@ -29,15 +29,10 @@ class ClearCacheQueryRegionCommandTest extends OrmFunctionalTestCase
$this->enableSecondLevelCache();
parent::setUp();
$this->application = new Application();
$this->command = new QueryRegionCommand();
$this->application->setHelperSet(new HelperSet(
[
'em' => new EntityManagerHelper($this->_em)
]
));
$this->application = new Application();
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)]));
$this->application->add($this->command);
}
@ -45,11 +40,13 @@ class ClearCacheQueryRegionCommandTest extends OrmFunctionalTestCase
{
$command = $this->application->find('orm:clear-cache:region:query');
$tester = new CommandTester($command);
$tester->execute(
[
'command' => $command->getName(),
'--all' => true,
], ['decorated' => false]
],
['decorated' => false]
);
$this->assertEquals('Clearing all second-level cache query regions' . PHP_EOL, $tester->getDisplay());
@ -59,11 +56,13 @@ class ClearCacheQueryRegionCommandTest extends OrmFunctionalTestCase
{
$command = $this->application->find('orm:clear-cache:region:query');
$tester = new CommandTester($command);
$tester->execute(
[
'command' => $command->getName(),
'region-name' => null,
], ['decorated' => false]
],
['decorated' => false]
);
$this->assertEquals('Clearing second-level cache query region named "query_cache_region"' . PHP_EOL, $tester->getDisplay());
@ -73,11 +72,13 @@ class ClearCacheQueryRegionCommandTest extends OrmFunctionalTestCase
{
$command = $this->application->find('orm:clear-cache:region:query');
$tester = new CommandTester($command);
$tester->execute(
[
'command' => $command->getName(),
'region-name' => 'my_region',
], ['decorated' => false]
],
['decorated' => false]
);
$this->assertEquals('Clearing second-level cache query region named "my_region"' . PHP_EOL, $tester->getDisplay());
@ -87,12 +88,14 @@ class ClearCacheQueryRegionCommandTest extends OrmFunctionalTestCase
{
$command = $this->application->find('orm:clear-cache:region:query');
$tester = new CommandTester($command);
$tester->execute(
[
'command' => $command->getName(),
'region-name' => 'my_region',
'--flush' => true,
], ['decorated' => false]
],
['decorated' => false]
);
$this->assertEquals('Flushing cache provider configured for second-level cache query region named "my_region"' . PHP_EOL, $tester->getDisplay());

View File

@ -2,18 +2,18 @@
namespace Doctrine\Tests\ORM\Tools\Console\Command;
use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Application;
use Doctrine\Tests\OrmFunctionalTestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Tester\CommandTester;
/**
* GenerateRepositoriesCommandTest
*/
class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase
{
/**
@ -34,25 +34,12 @@ class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase
\mkdir($this->path);
$metadataDriver = $this->_em->getConfiguration()->getMetadataDriverImpl();
$metadataDriver->addPaths(
[
__DIR__ . '/../../../../Models/DDC3231/'
]
);
$metadataDriver->addPaths([__DIR__ . '/../../../../Models/DDC3231/']);
$this->application = new Application();
$this->application->setHelperSet(new HelperSet(
[
'em' => new EntityManagerHelper($this->_em)
]
));
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)]));
$this->application->add(new GenerateRepositoriesCommand());
}
/**
@ -88,20 +75,20 @@ class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase
$cname = 'Doctrine\Tests\Models\DDC3231\DDC3231User1Repository';
$fname = str_replace('\\', DIRECTORY_SEPARATOR, $cname) . '.php';
$this->assertFileExists($this->path . DIRECTORY_SEPARATOR . $fname);
$this->assertFileExists($this->path . DIRECTORY_SEPARATOR . 'DDC3231User1NoNamespaceRepository.php');
self::assertFileExists($this->path . DIRECTORY_SEPARATOR . $fname);
self::assertFileExists($this->path . DIRECTORY_SEPARATOR . 'DDC3231User1NoNamespaceRepository.php');
require $this->path . DIRECTORY_SEPARATOR . $fname;
require $this->path . DIRECTORY_SEPARATOR . 'DDC3231User1NoNamespaceRepository.php';
$this->assertTrue(class_exists($cname));
$this->assertTrue(class_exists('DDC3231User1NoNamespaceRepository'));
self::assertTrue(class_exists($cname));
self::assertTrue(class_exists('DDC3231User1NoNamespaceRepository'));
$repo1 = new \ReflectionClass($cname);
$repo2 = new \ReflectionClass('DDC3231User1NoNamespaceRepository');
$this->assertSame(EntityRepository::class, $repo1->getParentClass()->getName());
$this->assertSame(EntityRepository::class, $repo2->getParentClass()->getName());
self::assertSame(EntityRepository::class, $repo1->getParentClass()->getName());
self::assertSame(EntityRepository::class, $repo2->getParentClass()->getName());
}
public function testGenerateRepositoriesCustomDefaultRepository()
@ -111,20 +98,20 @@ class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase
$cname = 'Doctrine\Tests\Models\DDC3231\DDC3231User2Repository';
$fname = str_replace('\\', DIRECTORY_SEPARATOR, $cname) . '.php';
$this->assertFileExists($this->path . DIRECTORY_SEPARATOR . $fname);
$this->assertFileExists($this->path . DIRECTORY_SEPARATOR . 'DDC3231User2NoNamespaceRepository.php');
self::assertFileExists($this->path . DIRECTORY_SEPARATOR . $fname);
self::assertFileExists($this->path . DIRECTORY_SEPARATOR . 'DDC3231User2NoNamespaceRepository.php');
require $this->path . DIRECTORY_SEPARATOR . $fname;
require $this->path . DIRECTORY_SEPARATOR . 'DDC3231User2NoNamespaceRepository.php';
$this->assertTrue(class_exists($cname));
$this->assertTrue(class_exists('DDC3231User2NoNamespaceRepository'));
self::assertTrue(class_exists($cname));
self::assertTrue(class_exists('DDC3231User2NoNamespaceRepository'));
$repo1 = new \ReflectionClass($cname);
$repo2 = new \ReflectionClass('DDC3231User2NoNamespaceRepository');
$this->assertSame(DDC3231EntityRepository::class, $repo1->getParentClass()->getName());
$this->assertSame(DDC3231EntityRepository::class, $repo2->getParentClass()->getName());
self::assertSame(DDC3231EntityRepository::class, $repo1->getParentClass()->getName());
self::assertSame(DDC3231EntityRepository::class, $repo2->getParentClass()->getName());
}
/**
@ -139,6 +126,7 @@ class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase
$command = $this->application->find('orm:generate-repositories');
$tester = new CommandTester($command);
$tester->execute(
[
'command' => $command->getName(),

View File

@ -2,6 +2,10 @@
namespace Doctrine\Tests\ORM\Tools\Console\Command;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\Tests\Models\Cache\AttractionInfo;
use Doctrine\Tests\Models\Cache\City;
@ -33,23 +37,19 @@ class InfoCommandTest extends OrmFunctionalTestCase
parent::setUp();
$this->application = new Application();
$command = new InfoCommand();
$this->application->setHelperSet(
new HelperSet(['em' => new EntityManagerHelper($this->_em)])
);
$this->application->add($command);
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)]));
$this->application->add(new InfoCommand());
$this->command = $this->application->find('orm:info');
$this->tester = new CommandTester($command);
$this->tester = new CommandTester($this->command);
}
public function testListAllClasses()
{
$this->tester->execute(['command' => $this->command->getName()]);
$this->assertContains(AttractionInfo::class, $this->tester->getDisplay());
$this->assertContains(City::class, $this->tester->getDisplay());
self::assertContains(AttractionInfo::class, $this->tester->getDisplay());
self::assertContains(City::class, $this->tester->getDisplay());
}
}

View File

@ -37,18 +37,11 @@ class MappingDescribeCommandTest extends OrmFunctionalTestCase
parent::setUp();
$this->application = new Application();
$command = new MappingDescribeCommand();
$this->application->setHelperSet(new HelperSet(
[
'em' => new EntityManagerHelper($this->_em)
]
));
$this->application->add($command);
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)]));
$this->application->add(new MappingDescribeCommand());
$this->command = $this->application->find('orm:mapping:describe');
$this->tester = new CommandTester($command);
$this->tester = new CommandTester($this->command);
}
public function testShowSpecificFuzzySingle()
@ -61,8 +54,9 @@ class MappingDescribeCommandTest extends OrmFunctionalTestCase
);
$display = $this->tester->getDisplay();
$this->assertContains(AttractionInfo::class, $display);
$this->assertContains('Root entity name', $display);
self::assertContains(AttractionInfo::class, $display);
self::assertContains('Root entity name', $display);
}
/**
@ -88,7 +82,7 @@ class MappingDescribeCommandTest extends OrmFunctionalTestCase
$this->tester->execute(
[
'command' => $this->command->getName(),
'entityName' => 'AttractionFooBar'
'entityName' => 'AttractionFooBar',
]
);
}

View File

@ -38,15 +38,10 @@ class RunDqlCommandTest extends OrmFunctionalTestCase
parent::setUp();
$this->application = new Application();
$this->command = new RunDqlCommand();
$this->application->setHelperSet(new HelperSet(
[
'em' => new EntityManagerHelper($this->_em)
]
));
$this->application = new Application();
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)]));
$this->application->add($this->command);
$this->tester = new CommandTester($this->command);
@ -54,7 +49,7 @@ class RunDqlCommandTest extends OrmFunctionalTestCase
public function testCommandName()
{
$this->assertSame($this->command, $this->application->get('orm:run-dql'));
self::assertSame($this->command, $this->application->get('orm:run-dql'));
}
public function testWillRunQuery()
@ -62,7 +57,7 @@ class RunDqlCommandTest extends OrmFunctionalTestCase
$this->_em->persist(new DateTimeModel());
$this->_em->flush();
$this->assertSame(
self::assertSame(
0,
$this->tester->execute(
[
@ -72,7 +67,7 @@ class RunDqlCommandTest extends OrmFunctionalTestCase
)
);
$this->assertContains(DateTimeModel::class, $this->tester->getDisplay());
self::assertContains(DateTimeModel::class, $this->tester->getDisplay());
}
public function testWillShowQuery()
@ -80,17 +75,17 @@ class RunDqlCommandTest extends OrmFunctionalTestCase
$this->_em->persist(new DateTimeModel());
$this->_em->flush();
$this->assertSame(
self::assertSame(
0,
$this->tester->execute(
[
'command' => $this->command->getName(),
'dql' => 'SELECT e FROM ' . DateTimeModel::class . ' e',
'--show-sql' => 'true'
'--show-sql' => 'true',
]
)
);
$this->assertStringMatchesFormat('%Astring%sSELECT %a', $this->tester->getDisplay());
self::assertStringMatchesFormat('%Astring%sSELECT %a', $this->tester->getDisplay());
}
}