File tree Expand file tree Collapse file tree 4 files changed +31
-8
lines changed Expand file tree Collapse file tree 4 files changed +31
-8
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,11 @@ protected function removeItem(mixed $item): self
3232 return $ this ;
3333 }
3434
35+ protected function containsItem (mixed $ item ): bool
36+ {
37+ return array_search ($ item , $ this ->items ) !== false ;
38+ }
39+
3540 public function itemsIterator (): \Generator
3641 {
3742 foreach ($ this ->items as $ item ) {
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ final class CollectionTest extends \PHPUnit\Framework\TestCase
1111{
1212 public function testInterface (): void
1313 {
14+ $ value = new Value ('Foo ' );
15+
1416 $ collection = new Collection ();
1517
1618 $ this ->assertIsBool ($ collection ->isEmpty ());
@@ -19,10 +21,14 @@ public function testInterface(): void
1921 $ this ->assertIsInt ($ collection ->getNbItems ());
2022 $ this ->assertEquals (0 , $ collection ->getNbItems ());
2123
22- $ collection ->addValue (
23- new Value ('Foo ' )
24+ $ this ->assertEquals (false , $ collection ->contains ($ value ));
25+
26+ $ collection ->add (
27+ $ value
2428 );
2529
30+ $ this ->assertEquals (true , $ collection ->contains ($ value ));
31+
2632 $ this ->assertEquals (false , $ collection ->isEmpty ());
2733 $ this ->assertEquals (1 , $ collection ->getNbItems ());
2834
@@ -32,15 +38,15 @@ public function testInterface(): void
3238 $ this ->assertIsObject ($ item );
3339 }
3440
35- $ collection ->removeValue (
36- new Value ( ' Foo ' )
41+ $ collection ->remove (
42+ $ value
3743 );
3844
3945 $ this ->assertEquals (true , $ collection ->isEmpty ());
4046 $ this ->assertEquals (0 , $ collection ->getNbItems ());
4147
42- $ collection ->addValue (
43- new Value ( ' Bar ' )
48+ $ collection ->add (
49+ $ value
4450 );
4551 }
4652}
Original file line number Diff line number Diff line change 88
99class Collection extends \Phant \DataStructure \Abstract \Collection
1010{
11- public function addValue (Value $ item )
11+ public function add (Value $ item )
1212 {
1313 parent ::addItem ($ item );
1414 }
1515
16- public function removeValue (Value $ item ): self
16+ public function remove (Value $ item ): self
1717 {
1818 return parent ::removeItem ($ item );
1919 }
20+
21+ public function contains (Value $ item ): bool
22+ {
23+ return parent ::containsItem ($ item );
24+ }
2025}
Original file line number Diff line number Diff line change @@ -26,4 +26,11 @@ public function testNotCompliant(): void
2626
2727 new Varchar ('' );
2828 }
29+
30+ public function testAddNonBreakingSpace (): void
31+ {
32+ $ string = (new Varchar ('Hello world! ' ))->addNonBreakingSpace ();
33+
34+ $ this ->assertEquals ('Hello ' . "\xC2\xA0" . 'world! ' , $ string );
35+ }
2936}
You can’t perform that action at this time.
0 commit comments