1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Bundle\DoctrineStaticWebsiteGeneratorBundle\Tests\Command; |
6
|
|
|
|
7
|
|
|
use Doctrine\Bundle\DoctrineStaticWebsiteGeneratorBundle\Command\BuildWebsiteCommand; |
8
|
|
|
use Doctrine\StaticWebsiteGenerator\SourceFile\SourceFileRepository; |
9
|
|
|
use Doctrine\StaticWebsiteGenerator\SourceFile\SourceFiles; |
10
|
|
|
use Doctrine\StaticWebsiteGenerator\SourceFile\SourceFilesBuilder; |
11
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use ReflectionClass; |
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
use function sys_get_temp_dir; |
17
|
|
|
|
18
|
|
|
class BuildWebsiteCommandTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** @var SourceFileRepository|MockObject */ |
21
|
|
|
private $sourceFileRepository; |
22
|
|
|
|
23
|
|
|
/** @var SourceFilesBuilder|MockObject */ |
24
|
|
|
private $sourceFilesBuilder; |
25
|
|
|
|
26
|
|
|
/** @var string */ |
27
|
|
|
private $buildDir; |
28
|
|
|
|
29
|
|
|
/** @var BuildWebsiteCommand */ |
30
|
|
|
private $buildWebsiteCommand; |
31
|
|
|
|
32
|
|
|
public function testConfigure() : void |
33
|
|
|
{ |
34
|
|
|
$this->invokeMethod($this->buildWebsiteCommand, 'configure'); |
35
|
|
|
|
36
|
|
|
self::assertSame('doctrine:build-website', $this->buildWebsiteCommand->getName()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testExecute() : void |
40
|
|
|
{ |
41
|
|
|
$input = $this->createMock(InputInterface::class); |
42
|
|
|
$output = $this->createMock(OutputInterface::class); |
43
|
|
|
|
44
|
|
|
$sourceFiles = new SourceFiles([]); |
45
|
|
|
|
46
|
|
|
$this->sourceFileRepository->expects(self::once()) |
47
|
|
|
->method('getSourceFiles') |
48
|
|
|
->with($this->buildDir) |
49
|
|
|
->willReturn($sourceFiles); |
50
|
|
|
|
51
|
|
|
$this->sourceFilesBuilder->expects(self::once()) |
52
|
|
|
->method('buildSourceFiles') |
53
|
|
|
->with($sourceFiles); |
54
|
|
|
|
55
|
|
|
$this->invokeMethod($this->buildWebsiteCommand, 'execute', [ |
56
|
|
|
$input, |
57
|
|
|
$output, |
58
|
|
|
]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
protected function setUp() : void |
62
|
|
|
{ |
63
|
|
|
$this->sourceFileRepository = $this->createMock(SourceFileRepository::class); |
64
|
|
|
$this->sourceFilesBuilder = $this->createMock(SourceFilesBuilder::class); |
65
|
|
|
$this->buildDir = sys_get_temp_dir() . '/build'; |
66
|
|
|
|
67
|
|
|
$this->buildWebsiteCommand = new BuildWebsiteCommand( |
68
|
|
|
$this->sourceFileRepository, |
69
|
|
|
$this->sourceFilesBuilder, |
70
|
|
|
$this->buildDir |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param object $object |
76
|
|
|
* @param mixed[] $parameters |
77
|
|
|
* |
78
|
|
|
* @return mixed |
79
|
|
|
*/ |
80
|
|
|
private function invokeMethod($object, string $methodName, array $parameters = []) |
81
|
|
|
{ |
82
|
|
|
$reflection = new ReflectionClass($object); |
83
|
|
|
$method = $reflection->getMethod($methodName); |
84
|
|
|
$method->setAccessible(true); |
85
|
|
|
|
86
|
|
|
return $method->invokeArgs($object, $parameters); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|