Skip to content

Commit b540de3

Browse files
committed
Implement tests
1 parent 458b160 commit b540de3

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

test.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
if (ini_get('zend.assertions') !== '1') {
4+
throw new LogicException('Tests are expecting `zend.assertions` set to 1 in php.ini.');
5+
}
6+
7+
if (ini_get('assert.exception') !== '1') {
8+
throw new LogicException('Tests are expecting `assert.exception` set to 1 in php.ini.');
9+
}
10+
11+
require __DIR__ . '/vendor/autoload.php';
12+
13+
$status = (function() {
14+
$total = 0;
15+
$passed = 0;
16+
$failed = 0;
17+
$finished = false;
18+
19+
register_shutdown_function(function () use (&$finished) {
20+
if (! $finished) {
21+
echo 'Not all tests were executed.', PHP_EOL;
22+
return 1;
23+
}
24+
return 0;
25+
});
26+
27+
$tests = [];
28+
29+
foreach (scandir(__DIR__ . '/tests') as $file) {
30+
if (substr($file, 0, 10) === 'it_should_') {
31+
$tests[] = $file;
32+
}
33+
}
34+
35+
$errors = [];
36+
37+
foreach ($tests as $file) {
38+
$total++;
39+
try {
40+
require __DIR__ . '/tests/' . $file;
41+
$passed++;
42+
echo '.';
43+
} catch (Throwable $exception) {
44+
echo 'E';
45+
$failed++;
46+
$errors[$file] = $exception;
47+
}
48+
}
49+
50+
echo " {$total}/{$total} (100%)", PHP_EOL;
51+
52+
if ($failed > 0) {
53+
echo "There were {$failed} errors: ", PHP_EOL;
54+
}
55+
56+
foreach (array_keys($errors) as $i => $test) {
57+
echo PHP_EOL;
58+
$exception = $errors[$test];
59+
echo sprintf("%s) %s", $i + 1, $test), PHP_EOL;
60+
echo sprintf("`%s` was thrown.", get_class($exception)), PHP_EOL;
61+
echo sprintf('"%s"', $exception->getMessage()), PHP_EOL;
62+
echo $exception->getTraceAsString(), PHP_EOL;
63+
}
64+
65+
echo PHP_EOL;
66+
67+
echo "Tests executed: {$total}", PHP_EOL;
68+
echo "Passed: {$passed}", PHP_EOL;
69+
echo "Failed: {$failed}", PHP_EOL;
70+
71+
$finished = true;
72+
73+
return $failed === 0 ? 0 : 1;
74+
})();
75+
76+
exit($status);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use Psr\Container\ContainerInterface;
4+
use Technically\NullContainer\NullContainer;
5+
6+
$container = new NullContainer();
7+
8+
assert($container->has('a') === false);
9+
assert($container->has('b') === false);
10+
assert($container->has('c') === false);
11+
assert($container->has(NullContainer::class) === false);
12+
assert($container->has(ContainerInterface::class) === false);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
use Psr\Container\NotFoundExceptionInterface;
4+
use Technically\NullContainer\Exceptions\ServiceNotFound;
5+
use Technically\NullContainer\NullContainer;
6+
7+
$container = new NullContainer();
8+
9+
try {
10+
$container->get('a');
11+
} catch (ServiceNotFound $exception) {
12+
// passthru
13+
}
14+
15+
assert(isset($exception));
16+
assert($exception instanceof ServiceNotFound);
17+
assert($exception instanceof NotFoundExceptionInterface);

tests/it_should_instantiate.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
use Technically\NullContainer\NullContainer;
4+
5+
$container = new NullContainer();
6+
7+
assert($container instanceof NullContainer);

0 commit comments

Comments
 (0)