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
|
|
|
/** |
19
|
|
|
* @dataProvider provideExampleData |
20
|
|
|
*/ |
21
|
|
|
public function testExample(string $filename) : void |
22
|
|
|
{ |
23
|
|
|
$uri = ClientBuilder::createFromEnv()->getUri(); |
24
|
|
|
|
25
|
|
|
exec("php $filename $uri", $output, $exitCode); |
26
|
|
|
|
27
|
|
|
$flattenOutput = implode("\n", $output); |
28
|
|
|
if (0 === strpos($flattenOutput, 'Unfulfilled requirement:')) { |
29
|
|
|
self::markTestSkipped($flattenOutput); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
self::assertSame(0, $exitCode, $flattenOutput); |
33
|
|
|
|
34
|
|
|
$expectedOutput = self::parseFile($filename); |
35
|
|
|
if (null !== $expectedOutput) { |
36
|
|
|
self::assertSame($expectedOutput, $flattenOutput); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function provideExampleData() : iterable |
41
|
|
|
{ |
42
|
|
|
$dir = dirname(__DIR__, 2).'/examples'; |
43
|
|
|
foreach (glob("$dir/{**/*,*}.php", GLOB_BRACE) as $filename) { |
44
|
|
|
$basename = basename($filename, '.php'); |
45
|
|
|
if ('bootstrap' === $basename) { |
46
|
|
|
continue; |
47
|
|
|
} |
48
|
|
|
// Ignore classes |
49
|
|
|
if (strtolower($basename[0]) !== $basename[0]) { |
50
|
|
|
continue; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
yield [$filename]; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
private static function parseFile(string $filename) : ?string |
58
|
|
|
{ |
59
|
|
|
$content = file_get_contents($filename); |
60
|
|
|
if (preg_match('~/\*\s*?OUTPUT\b(.+?)\*/~s', $content, $matches)) { |
61
|
|
|
return trim($matches[1]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return null; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|