1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Markus Tacker <[email protected]> |
5
|
|
|
* @copyright 2013-2016 Verein zur Förderung der Netzkultur im Rhein-Main-Gebiet e.V. | http://netzkultur-rheinmain.de/ |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace BCRM\WebBundle\Tests\Functional; |
9
|
|
|
|
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
12
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
13
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
14
|
|
|
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\CreateSchemaDoctrineCommand; |
15
|
|
|
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\DropSchemaDoctrineCommand; |
16
|
|
|
use Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand; |
17
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
18
|
|
|
use PhpOption\Option; |
19
|
|
|
use Symfony\Component\Console\Command\Command; |
20
|
|
|
|
21
|
|
|
abstract class Base extends WebTestCase |
22
|
|
|
{ |
23
|
|
|
protected static function resetDatabase() |
24
|
|
|
{ |
25
|
|
|
$client = static::createClient(); |
26
|
|
|
$container = $client->getContainer(); |
27
|
|
|
static::runCommand($container, new DropSchemaDoctrineCommand(), 'doctrine:schema:drop', array('--force' => true)); |
|
|
|
|
28
|
|
|
static::runCommand($container, new CreateSchemaDoctrineCommand(), 'doctrine:schema:create'); |
|
|
|
|
29
|
|
|
static::runCommand($container, new LoadDataFixturesDoctrineCommand(), 'doctrine:fixtures:load', array('--append' => true, '--fixtures' => './src/BCRM/BackendBundle/Tests/data/fixtures/')); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Executes a console command. |
34
|
|
|
* |
35
|
|
|
* @param ContainerInterface $container |
36
|
|
|
* @param Command $command |
37
|
|
|
* @param string $alias |
38
|
|
|
* @param array $args |
39
|
|
|
*/ |
40
|
|
|
protected static function runCommand(ContainerInterface $container, Command $command, $alias, array $args = null) |
41
|
|
|
{ |
42
|
|
|
$application = new Application(static::$kernel); |
43
|
|
|
$application->setAutoExit(false); |
44
|
|
|
$application->add($command); |
45
|
|
|
|
46
|
|
|
$command = $application->find($alias); |
47
|
|
|
if ($command instanceof ContainerAwareCommand) { |
48
|
|
|
$command->setContainer($container); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$commandTester = new CommandTester($command); |
52
|
|
|
$call = array_merge(Option::fromValue($args)->getOrElse(array()), array('command' => $command->getName())); |
53
|
|
|
$commandTester->execute($call); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Asserts that $needle is in $haystack. |
58
|
|
|
* |
59
|
|
|
* @param $needle |
60
|
|
|
* @param $haystack |
61
|
|
|
*/ |
62
|
|
|
protected function assertInArray($needle, $haystack) |
63
|
|
|
{ |
64
|
|
|
$this->assertTrue(in_array($needle, $haystack), sprintf('Failed asserting that %s is not in array.', $needle)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Asserts that $needle is not in $haystack. |
69
|
|
|
* |
70
|
|
|
* @param $needle |
71
|
|
|
* @param $haystack |
72
|
|
|
*/ |
73
|
|
|
protected function assertNotInArray($needle, $haystack) |
74
|
|
|
{ |
75
|
|
|
$this->assertFalse(in_array($needle, $haystack), sprintf('Failed asserting that %s is not in array.', $needle)); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: