|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Tarantool Client package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Eugene Leonovich <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Tarantool\Client\Tests\Integration; |
|
15
|
|
|
|
|
16
|
|
|
final class ExamplesTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
public const EXIT_CODE_SKIP = 42; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @dataProvider provideExampleData |
|
22
|
|
|
*/ |
|
23
|
|
|
public function testExample(string $filename) : void |
|
24
|
|
|
{ |
|
25
|
|
|
$uri = ClientBuilder::createFromEnv()->getUri(); |
|
26
|
|
|
|
|
27
|
|
|
exec("php $filename $uri", $output, $exitCode); |
|
28
|
|
|
|
|
29
|
|
|
if (self::EXIT_CODE_SKIP === $exitCode) { |
|
30
|
|
|
self::markTestSkipped(implode("\n", $output)); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
self::assertSame(0, $exitCode, implode("\n", $output)); |
|
34
|
|
|
|
|
35
|
|
|
$expectedOutput = self::parseFile($filename); |
|
36
|
|
|
if (null !== $expectedOutput) { |
|
37
|
|
|
self::assertSame($expectedOutput, implode("\n", $output)); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function provideExampleData() : iterable |
|
42
|
|
|
{ |
|
43
|
|
|
$dir = dirname(__DIR__, 2).'/examples'; |
|
44
|
|
|
foreach (glob("$dir/{**/*,*}.php", GLOB_BRACE) as $filename) { |
|
45
|
|
|
$basename = basename($filename, '.php'); |
|
46
|
|
|
if ('bootstrap' === $basename) { |
|
47
|
|
|
continue; |
|
48
|
|
|
} |
|
49
|
|
|
// ignore classes |
|
50
|
|
|
if (strtolower($basename[0]) !== $basename[0]) { |
|
51
|
|
|
continue; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
yield [$filename]; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
private static function parseFile(string $filename) : ?string |
|
59
|
|
|
{ |
|
60
|
|
|
$content = file_get_contents($filename); |
|
61
|
|
|
if (preg_match('~\/\*\s*?OUTPUT\b(.+?)\*\/~s', $content, $matches)) { |
|
62
|
|
|
return trim($matches[1]); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return null; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|