1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Container.php |
||
5 | * |
||
6 | * This file demonstrate how to add values to the suite storage container |
||
7 | * and use it inside the tests. |
||
8 | * |
||
9 | * PHP version 7.4 |
||
10 | * |
||
11 | * @category Examples |
||
12 | * @package RedboxTestSuite |
||
13 | * @author Johnny Mast <[email protected]> |
||
14 | * @license https://opensource.org/licenses/MIT MIT |
||
15 | * @link https://github.com/johnnymast/redbox-testsuite |
||
16 | * @since 1.0 |
||
17 | */ |
||
18 | |||
19 | require __DIR__.'/../vendor/autoload.php'; |
||
20 | |||
21 | use Redbox\Testsuite\Interfaces\ContainerInterface; |
||
22 | use Redbox\Testsuite\TestCase; |
||
23 | use Redbox\Testsuite\TestSuite; |
||
24 | |||
25 | /** |
||
26 | * Class MyFirstTest |
||
27 | */ |
||
28 | class MyFirstTestCase extends TestCase |
||
29 | { |
||
30 | |||
31 | /** |
||
32 | * Tell the TestCase what the |
||
33 | * min reachable score is. |
||
34 | * |
||
35 | * @var int |
||
36 | */ |
||
37 | protected int $minscore = 0; |
||
38 | |||
39 | /** |
||
40 | * Tell the TestCase what the |
||
41 | * max reachable score is. |
||
42 | * |
||
43 | * @var int |
||
44 | */ |
||
45 | protected int $maxscore = 10; |
||
46 | |||
47 | /** |
||
48 | * Demo function show how values are passed. |
||
49 | * |
||
50 | * @param string $word Word to echo. |
||
51 | * |
||
52 | * @return void |
||
53 | */ |
||
54 | protected function say(string $word): void |
||
55 | { |
||
56 | echo $word."\n"; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Run the test. |
||
61 | * |
||
62 | * @param ContainerInterface $container The storage container for the TestSuite. |
||
63 | * |
||
64 | * @return bool |
||
65 | */ |
||
66 | public function run(ContainerInterface $container) |
||
67 | { |
||
68 | if ($container->has('words')) { |
||
69 | $words = $container->get('words'); |
||
70 | |||
71 | foreach ($words as $word) { |
||
72 | $this->say($word); |
||
73 | } |
||
74 | } |
||
75 | |||
76 | return true; |
||
0 ignored issues
–
show
|
|||
77 | } |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Instantiate the test. |
||
82 | */ |
||
83 | $testInstance = new MyFirstTestCase(); |
||
84 | |||
85 | /** |
||
86 | * Create a test suite and attach the test. |
||
87 | */ |
||
88 | $suite = new TestSuite(); |
||
89 | $suite->attach($testInstance); |
||
90 | |||
91 | $suite->getContainer()->set('words', ["Hello", "2021", "How", "Are", "You?"]); |
||
92 | |||
93 | $suite->run(); |
||
94 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: