My attempts at exercism.org
1<?php
2
3/*
4 * By adding type hints and enabling strict type checking, code can become
5 * easier to read, self-documenting and reduce the number of potential bugs.
6 * By default, type declarations are non-strict, which means they will attempt
7 * to change the original type to match the type specified by the
8 * type-declaration.
9 *
10 * In other words, if you pass a string to a function requiring a float,
11 * it will attempt to convert the string value to a float.
12 *
13 * To enable strict mode, a single declare directive must be placed at the top
14 * of the file.
15 * This means that the strictness of typing is configured on a per-file basis.
16 * This directive not only affects the type declarations of parameters, but also
17 * a function's return type.
18 *
19 * For more info review the Concept on strict type checking in the PHP track
20 * <link>.
21 *
22 * To disable strict typing, comment out the directive below.
23 */
24
25declare(strict_types=1);
26
27use PHPUnit\Framework\TestCase;
28
29class ProverbTest extends TestCase
30{
31 private Proverb $proverb;
32
33 public static function setUpBeforeClass(): void
34 {
35 require_once 'Proverb.php';
36 }
37
38 public function setUp(): void
39 {
40 $this->proverb = new Proverb();
41 }
42
43 public function testNoVerses(): void
44 {
45 $pieces = [];
46 $expected = [];
47 $this->assertEquals($expected, $this->proverb->recite($pieces));
48 }
49
50 public function testOneVerse(): void
51 {
52 $pieces = ['nail'];
53 $expected = ['And all for the want of a nail.'];
54 $this->assertEquals($expected, $this->proverb->recite($pieces));
55 }
56
57 public function testTwoVerses(): void
58 {
59 $pieces = ['nail', 'shoe'];
60 $expected = ['For want of a nail the shoe was lost.', 'And all for the want of a nail.'];
61 $this->assertEquals($expected, $this->proverb->recite($pieces));
62 }
63
64 public function testThreeVerses(): void
65 {
66 $pieces = ['nail', 'shoe', 'horse'];
67 $expected = [
68 'For want of a nail the shoe was lost.',
69 'For want of a shoe the horse was lost.',
70 'And all for the want of a nail.'
71 ];
72 $this->assertEquals($expected, $this->proverb->recite($pieces));
73 }
74
75 public function testFullProverb(): void
76 {
77 $pieces = ['nail', 'shoe', 'horse', 'rider', 'message', 'battle', 'kingdom'];
78 $expected = [
79 'For want of a nail the shoe was lost.',
80 'For want of a shoe the horse was lost.',
81 'For want of a horse the rider was lost.',
82 'For want of a rider the message was lost.',
83 'For want of a message the battle was lost.',
84 'For want of a battle the kingdom was lost.',
85 'And all for the want of a nail.'
86 ];
87 $this->assertEquals($expected, $this->proverb->recite($pieces));
88 }
89
90 public function testFourModernizedVerses(): void
91 {
92 $pieces = ['pin', 'gun', 'soldier', 'battle'];
93 $expected = [
94 'For want of a pin the gun was lost.',
95 'For want of a gun the soldier was lost.',
96 'For want of a soldier the battle was lost.',
97 'And all for the want of a pin.'
98 ];
99 $this->assertEquals($expected, $this->proverb->recite($pieces));
100 }
101}