|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bicycle\TesseractBridgeBundle\Tests\DataCollector; |
|
4
|
|
|
|
|
5
|
|
|
use Bicycle\Tesseract\Bridge; |
|
6
|
|
|
use Bicycle\TesseractBridgeBundle\DataCollector\TesseractBridgeDataCollector; |
|
7
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
|
|
12
|
|
|
class TesseractBridgeDataCollectorTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var Request|MockObject */ |
|
15
|
|
|
private Request $requestMock; |
|
16
|
|
|
|
|
17
|
|
|
/** @var Response|MockObject */ |
|
18
|
|
|
private Response $responseMock; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* {@inheritDoc} |
|
22
|
|
|
*/ |
|
23
|
|
|
protected function setUp(): void |
|
24
|
|
|
{ |
|
25
|
|
|
parent::setUp(); |
|
26
|
|
|
$this->requestMock = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock(); |
|
27
|
|
|
$this->requestMock->expects(self::never())->method(self::anything()); |
|
|
|
|
|
|
28
|
|
|
$this->responseMock = $this->getMockBuilder(Response::class)->disableOriginalConstructor()->getMock(); |
|
29
|
|
|
$this->responseMock->expects(self::never())->method(self::anything()); |
|
|
|
|
|
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testCollectEmptyConfiguration(): void |
|
33
|
|
|
{ |
|
34
|
|
|
$testInstance = new TesseractBridgeDataCollector(null, null, []); |
|
35
|
|
|
$testInstance->collect($this->requestMock, $this->responseMock); |
|
36
|
|
|
self::assertEquals(TesseractBridgeDataCollector::NAME, $testInstance->getName()); |
|
37
|
|
|
self::assertEquals(extension_loaded('ffi'), $testInstance->hasFFI()); |
|
38
|
|
|
self::assertFalse($testInstance->isCliIntegrationEnabled()); |
|
39
|
|
|
self::assertFalse($testInstance->isFFIIntegrationEnabled()); |
|
40
|
|
|
self::assertEquals([], $testInstance->getCliIntegrationData()); |
|
41
|
|
|
self::assertEquals([], $testInstance->getFfiIntegrationData()); |
|
42
|
|
|
$testInstance->reset(); |
|
43
|
|
|
self::assertFalse($testInstance->isCliIntegrationEnabled()); |
|
44
|
|
|
self::assertFalse($testInstance->isFFIIntegrationEnabled()); |
|
45
|
|
|
self::assertEquals([], $testInstance->getCliIntegrationData()); |
|
46
|
|
|
self::assertEquals([], $testInstance->getFfiIntegrationData()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testCollectCliIntegrationEnabled(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$testCliVersion = 'test cli version'; |
|
52
|
|
|
$testCliLanguages = ['lang1', 'lang2']; |
|
53
|
|
|
$configuration = ['integrations' => ['cli' => ['enabled' => true]]]; |
|
54
|
|
|
$cliIntegrationMock = $this->getMockBuilder(Bridge\CLI::class)->disableOriginalConstructor()->getMock(); |
|
55
|
|
|
$cliIntegrationMock->expects(self::once())->method('getVersion')->willReturn($testCliVersion); |
|
56
|
|
|
$cliIntegrationMock->expects(self::once())->method('getAvailableLanguages')->willReturn($testCliLanguages); |
|
57
|
|
|
$testInstance = new TesseractBridgeDataCollector($cliIntegrationMock, null, $configuration); |
|
58
|
|
|
$testInstance->collect($this->requestMock, $this->responseMock); |
|
59
|
|
|
self::assertTrue($testInstance->isCliIntegrationEnabled()); |
|
60
|
|
|
self::assertFalse($testInstance->isFFIIntegrationEnabled()); |
|
61
|
|
|
self::assertEquals( |
|
62
|
|
|
['tesseractVersion' => $testCliVersion, 'availableLanguages' => $testCliLanguages], |
|
63
|
|
|
$testInstance->getCliIntegrationData() |
|
64
|
|
|
); |
|
65
|
|
|
self::assertEquals([], $testInstance->getFfiIntegrationData()); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return \string[][] |
|
70
|
|
|
*/ |
|
71
|
|
|
public function tesseractVersionDataProvider(): array |
|
72
|
|
|
{ |
|
73
|
|
|
return [ |
|
|
|
|
|
|
74
|
|
|
['test ffi version'], |
|
75
|
|
|
['4.0.0'], |
|
76
|
|
|
]; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @dataProvider tesseractVersionDataProvider |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $testFfiVersion |
|
83
|
|
|
*/ |
|
84
|
|
|
public function testCollectFfiIntegrationEnabled(string $testFfiVersion): void |
|
85
|
|
|
{ |
|
86
|
|
|
$testFfiLanguages = ['lang1', 'lang2']; |
|
87
|
|
|
$configuration = ['integrations' => ['ffi' => ['enabled' => true]]]; |
|
88
|
|
|
$ffiIntegrationMock = $this->getMockBuilder(Bridge\FFI::class)->disableOriginalConstructor()->getMock(); |
|
89
|
|
|
$ffiIntegrationMock->expects(self::once())->method('getVersion')->willReturn($testFfiVersion); |
|
90
|
|
|
$ffiIntegrationMock->expects(self::once())->method('getAvailableLanguages')->willReturn($testFfiLanguages); |
|
91
|
|
|
$testInstance = new TesseractBridgeDataCollector(null, $ffiIntegrationMock, $configuration); |
|
92
|
|
|
$testInstance->collect($this->requestMock, $this->responseMock); |
|
93
|
|
|
self::assertFalse($testInstance->isCliIntegrationEnabled()); |
|
94
|
|
|
self::assertTrue($testInstance->isFFIIntegrationEnabled()); |
|
95
|
|
|
self::assertEquals([], $testInstance->getCliIntegrationData()); |
|
96
|
|
|
self::assertEquals( |
|
97
|
|
|
['tesseractVersion' => $testFfiVersion, 'availableLanguages' => $testFfiLanguages], |
|
98
|
|
|
$testInstance->getFfiIntegrationData() |
|
99
|
|
|
); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.