Skip to content

Commit 97a3763

Browse files
committed
Updated testing process
1 parent 80bfdf1 commit 97a3763

File tree

6 files changed

+133
-68
lines changed

6 files changed

+133
-68
lines changed

install-development

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
# Example:
2121
# ./install-development --phpize /usr/bin/phpize5.6 --php-config /usr/bin/php-config5.6
2222

23-
set -e
24-
2523
export ZEND_DONT_UNLOAD_MODULES=1
2624
export USE_ZEND_ALLOC=0
2725

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
return [
4+
[
5+
'type' => 'namespace',
6+
'name' => 'Example',
7+
'file' => data_path('simple/example.zep'),
8+
'line' => 3,
9+
'char' => 5,
10+
],
11+
[
12+
'type' => 'class',
13+
'name' => 'Test',
14+
'abstract' => 0,
15+
'final' => 0,
16+
'definition' => [
17+
'properties' => [
18+
[
19+
'visibility' => ['public'],
20+
'type' => 'property',
21+
'name' => 'foo',
22+
'file' => data_path('simple/example.zep'),
23+
'line' => 6,
24+
'char' => 10,
25+
],
26+
[
27+
'visibility' => ['protected'],
28+
'type' => 'property',
29+
'name' => 'bar',
30+
'file' => data_path('simple/example.zep'),
31+
'line' => 7,
32+
'char' => 8,
33+
],
34+
[
35+
'visibility' => ['private'],
36+
'type' => 'property',
37+
'name' => 'baz',
38+
'file' => data_path('simple/example.zep'),
39+
'line' => 8,
40+
'char' => 1,
41+
],
42+
],
43+
'file' => data_path('simple/example.zep'),
44+
'line' => 3,
45+
'char' => 5,
46+
],
47+
'file' => data_path('simple/example.zep'),
48+
'line' => 3,
49+
'char' => 5,
50+
],
51+
];

unit-tests/Extension/ParserSimpleTest.php

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,6 @@ class ParserSimpleTest extends TestCase
77
/** @test */
88
public function shouldProperlyParseTheFile()
99
{
10-
$path = $this->dataPath('simple/example.zep');
11-
$expected = [
12-
[
13-
'type' => 'namespace',
14-
'name' => 'Example',
15-
'file' => $path,
16-
'line' => 3,
17-
'char' => 5,
18-
],
19-
[
20-
'type' => 'class',
21-
'name' => 'Test',
22-
'abstract' => 0,
23-
'final' => 0,
24-
'definition' => [
25-
'properties' => [
26-
[
27-
'visibility' => ['public'],
28-
'type' => 'property',
29-
'name' => 'foo',
30-
'file' => $path,
31-
'line' => 6,
32-
'char' => 10,
33-
],
34-
[
35-
'visibility' => ['protected'],
36-
'type' => 'property',
37-
'name' => 'bar',
38-
'file' => $path,
39-
'line' => 7,
40-
'char' => 8,
41-
],
42-
[
43-
'visibility' => ['private'],
44-
'type' => 'property',
45-
'name' => 'baz',
46-
'file' => $path,
47-
'line' => 8,
48-
'char' => 1,
49-
],
50-
],
51-
'file' => $path,
52-
'line' => 3,
53-
'char' => 5,
54-
],
55-
'file' => $path,
56-
'line' => 3,
57-
'char' => 5,
58-
],
59-
];
60-
61-
$this->assertSame($expected, $this->parseFile('simple/example.zep'));
10+
$this->assertSame(expected('simple/example.php'), $this->parseFile('simple/example.zep'));
6211
}
6312
}

unit-tests/Extension/TestCase.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,10 @@ public function setUp()
3838

3939
protected function parseFile($file)
4040
{
41-
$path = $this->dataPath($file);
41+
$path = data_path($file);
4242
return zephir_parse_file(file_get_contents($path), $path);
4343
}
4444

45-
protected function dataPath($path)
46-
{
47-
$normalized = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $path);
48-
return ZEPHIR_PARSER_DATA . DIRECTORY_SEPARATOR . ltrim($normalized, DIRECTORY_SEPARATOR);
49-
}
50-
5145
/**
5246
* Clean output directory from the generated files.
5347
*/
@@ -64,15 +58,20 @@ protected function cleanOutputDir()
6458
new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::CHILD_FIRST)
6559
);
6660

67-
foreach ($iterator as $file) {
61+
try {
62+
foreach ($iterator as $file) {
6863
/* @var \SplFileInfo $file */
69-
if ($file->isFile()) {
70-
if (strpos($file->getBasename(), '.') !== 0) {
71-
unlink($file->getRealPath());
72-
} elseif ($file->isDir()) {
73-
rmdir($file->getRealPath());
74-
}
64+
if ($file->isDir()) {
65+
rmdir($file->getRealPath());
66+
continue;
7567
}
68+
69+
if (strpos($file->getBasename(), '.') !== 0) {
70+
unlink($file->getRealPath());
71+
}
72+
}
73+
} catch (\UnexpectedValueException $e) {
74+
// Ignore
7675
}
7776
}
7877
}

unit-tests/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@
5555
define('ZEPHIR_PARSER_TESTS_ROOT', __DIR__);
5656
define('ZEPHIR_PARSER_DATA', __DIR__ . DIRECTORY_SEPARATOR . 'Data');
5757
define('ZEPHIR_PARSER_OUTPUT', __DIR__ . DIRECTORY_SEPARATOR . 'Output');
58+
define('ZEPHIR_PARSER_EXPECTED', __DIR__ . DIRECTORY_SEPARATOR . 'Expected');

unit-tests/functions.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,70 @@ function dd()
3333
die(1);
3434
}
3535
}
36+
37+
if (!function_exists('expected')) {
38+
/**
39+
* Get the expected content.
40+
*
41+
* @param string $path
42+
* @return string
43+
*/
44+
function expected($path)
45+
{
46+
return require expected_path($path);
47+
}
48+
}
49+
50+
if (!function_exists('data_path')) {
51+
/**
52+
* Get the data path.
53+
*
54+
* @param string $path
55+
* @return string
56+
*/
57+
function data_path($path = '')
58+
{
59+
if ($path) {
60+
$normalized = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $path);
61+
$path = DIRECTORY_SEPARATOR . ltrim($normalized, DIRECTORY_SEPARATOR);
62+
}
63+
64+
return ZEPHIR_PARSER_DATA . $path;
65+
}
66+
}
67+
68+
if (!function_exists('output_path')) {
69+
/**
70+
* Get the output path.
71+
*
72+
* @param string $path
73+
* @return string
74+
*/
75+
function output_path($path = '')
76+
{
77+
if ($path) {
78+
$normalized = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $path);
79+
$path = DIRECTORY_SEPARATOR . ltrim($normalized, DIRECTORY_SEPARATOR);
80+
}
81+
82+
return ZEPHIR_PARSER_OUTPUT . $path;
83+
}
84+
}
85+
86+
if (!function_exists('expected_path')) {
87+
/**
88+
* Get the expected path.
89+
*
90+
* @param string $path
91+
* @return string
92+
*/
93+
function expected_path($path = '')
94+
{
95+
if ($path) {
96+
$normalized = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $path);
97+
$path = DIRECTORY_SEPARATOR . ltrim($normalized, DIRECTORY_SEPARATOR);
98+
}
99+
100+
return ZEPHIR_PARSER_EXPECTED . $path;
101+
}
102+
}

0 commit comments

Comments
 (0)