Skip to content

Commit 69f4de3

Browse files
committed
Add some contract tests
1 parent 6845eae commit 69f4de3

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

tests/InterfaceCompatibilityTest.php

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace FFI\Contracts\Preprocessor\Tests;
6+
7+
use FFI\Contracts\Preprocessor\Directive\DirectiveInterface;
8+
use FFI\Contracts\Preprocessor\Directive\FunctionLikeDirectiveInterface;
9+
use FFI\Contracts\Preprocessor\Directive\RegistrarInterface as DirectiveRegistrarInterface;
10+
use FFI\Contracts\Preprocessor\Directive\RepositoryInterface;
11+
use FFI\Contracts\Preprocessor\PreprocessorInterface;
12+
use FFI\Contracts\Preprocessor\ProvidesDirectivesInterface as DirectivesProviderInterface;
13+
use FFI\Contracts\Preprocessor\ProvidesDirectoriesInterface as DirectoriesProviderInterface;
14+
use FFI\Contracts\Preprocessor\ProvidesSourcesInterface as SourcesProviderInterface;
15+
use FFI\Contracts\Preprocessor\Io\Source\RepositoryInterface as SourceRepositoryInterface;
16+
use FFI\Contracts\Preprocessor\Directive\RepositoryInterface as DirectiveRepositoryInterface;
17+
use FFI\Contracts\Preprocessor\Io\Directory\RepositoryInterface as DirectoryRepositoryInterface;
18+
use FFI\Contracts\Preprocessor\ResultInterface;
19+
20+
/**
21+
* Note: Changing the behavior of these tests is allowed ONLY when updating
22+
* a MAJOR version of the package.
23+
*/
24+
final class InterfaceCompatibilityTest extends TestCase
25+
{
26+
public function testResultCompatibility(): void
27+
{
28+
$this->expectNotToPerformAssertions();
29+
30+
new class implements ResultInterface {
31+
public function __toString(): string {}
32+
public function getDirectives(): DirectiveRepositoryInterface {}
33+
public function getDirectories(): DirectoryRepositoryInterface {}
34+
public function getSources(): SourceRepositoryInterface {}
35+
};
36+
}
37+
38+
public function testProvidesSourcesCompatibility(): void
39+
{
40+
$this->expectNotToPerformAssertions();
41+
42+
new class implements SourcesProviderInterface {
43+
public function getSources(): SourceRepositoryInterface {}
44+
};
45+
}
46+
47+
public function testProvidesDirectoriesCompatibility(): void
48+
{
49+
$this->expectNotToPerformAssertions();
50+
51+
new class implements DirectoriesProviderInterface {
52+
public function getDirectories(): DirectoryRepositoryInterface {}
53+
};
54+
}
55+
56+
public function testProvidesDirectivesCompatibility(): void
57+
{
58+
$this->expectNotToPerformAssertions();
59+
60+
new class implements DirectivesProviderInterface {
61+
public function getDirectives(): DirectiveRepositoryInterface {}
62+
};
63+
}
64+
65+
public function testPreprocessorCompatibility(): void
66+
{
67+
$this->expectNotToPerformAssertions();
68+
69+
new class implements PreprocessorInterface {
70+
public function process($source): ResultInterface {}
71+
public function getDirectives(): DirectiveRepositoryInterface {}
72+
public function getDirectories(): DirectoryRepositoryInterface {}
73+
public function getSources(): SourceRepositoryInterface {}
74+
public function add(string $file, $source, bool $overwrite = false): bool {}
75+
public function remove(string $file): bool {}
76+
public function define(string $directive, $value = DirectiveInterface::DEFAULT_VALUE): void {}
77+
public function undef(string $directive): bool {}
78+
public function include(string $directory): void {}
79+
public function exclude(string $directory): void {}
80+
};
81+
}
82+
83+
public function testDirectiveCompatibility(): void
84+
{
85+
$this->expectNotToPerformAssertions();
86+
87+
new class implements DirectiveInterface {
88+
public function __invoke(): string {}
89+
};
90+
}
91+
92+
public function testFunctionLikeDirectiveCompatibility(): void
93+
{
94+
$this->expectNotToPerformAssertions();
95+
96+
new class implements FunctionLikeDirectiveInterface {
97+
public function __invoke(string ...$args): string {}
98+
public function getMaxArgumentsCount(): int {}
99+
public function getMinArgumentsCount(): int {}
100+
};
101+
}
102+
103+
public function testDirectiveRegistrarCompatibility(): void
104+
{
105+
$this->expectNotToPerformAssertions();
106+
107+
new class implements DirectiveRegistrarInterface {
108+
public function define(string $directive, $value = DirectiveInterface::DEFAULT_VALUE): void {}
109+
public function undef(string $directive): bool {}
110+
};
111+
}
112+
113+
public function testDirectiveRepositoryCompatibility(): void
114+
{
115+
$this->expectNotToPerformAssertions();
116+
117+
new class implements DirectiveRepositoryInterface, \IteratorAggregate {
118+
public function count(): int {}
119+
public function defined(string $directive): bool {}
120+
public function find(string $directive): ?DirectiveInterface {}
121+
public function getIterator(): \Traversable {}
122+
};
123+
}
124+
}

0 commit comments

Comments
 (0)