1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Zenify\DoctrineMigrations\Tests\EventSubscriber; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Migrations\Configuration\Configuration; |
8
|
|
|
use Nette\Utils\FileSystem; |
9
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
10
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class ChangeCodingStandardEventSubscriberTest extends AbstractEventSubscriberTest |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
protected function setUp() |
17
|
|
|
{ |
18
|
|
|
parent::setUp(); |
19
|
|
|
|
20
|
|
|
/** @var Configuration $configuration */ |
21
|
|
|
$configuration = $this->container->getByType(Configuration::class); |
22
|
|
|
$configuration->setMigrationsDirectory($this->getMigrationsDirectory()); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
public function testDispatchingGenerateCommand() |
27
|
|
|
{ |
28
|
|
|
$input = new ArrayInput(['command' => 'migrations:generate']); |
29
|
|
|
$output = new BufferedOutput; |
30
|
|
|
|
31
|
|
|
$result = $this->application->run($input, $output); |
32
|
|
|
$this->assertSame(0, $result); |
33
|
|
|
$this->assertCommandOutputAndMigrationCodeStyle($output->fetch()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
public function testDispatchingDiffCommand() |
38
|
|
|
{ |
39
|
|
|
$input = new ArrayInput(['command' => 'migrations:diff']); |
40
|
|
|
$output = new BufferedOutput; |
41
|
|
|
|
42
|
|
|
$result = $this->application->run($input, $output); |
43
|
|
|
$this->assertSame(0, $result); |
44
|
|
|
$this->assertCommandOutputAndMigrationCodeStyle($output->fetch()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $outputContent |
50
|
|
|
*/ |
51
|
|
|
private function assertCommandOutputAndMigrationCodeStyle($outputContent) |
52
|
|
|
{ |
53
|
|
|
$this->assertContains('Generated new migration class to', $outputContent); |
54
|
|
|
|
55
|
|
|
$migrationFile = $this->extractMigrationFile($outputContent); |
56
|
|
|
$fileContents = file_get_contents($migrationFile); |
57
|
|
|
$this->assertNotContains(' ', $fileContents); |
58
|
|
|
$this->assertContains("\t", $fileContents); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
private function getMigrationsDirectory() |
66
|
|
|
{ |
67
|
|
|
$migrationsDirectory = sys_get_temp_dir() . '/doctrine-migrations/Migrations'; |
68
|
|
|
FileSystem::createDir($migrationsDirectory); |
69
|
|
|
return $migrationsDirectory; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $outputContent |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
private function extractMigrationFile($outputContent) |
78
|
|
|
{ |
79
|
|
|
preg_match('/"([^"]+)"/', $outputContent, $matches); |
80
|
|
|
return $matches[1]; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
} |
84
|
|
|
|