1
+ <?php
2
+
3
+ namespace Http \HttplugBundle \Tests \Unit \ClientFactory ;
4
+
5
+ use Http \HttplugBundle \Collector \MessageJournal ;
6
+ use Http \HttplugBundle \HttplugFactory ;
7
+ use Puli \Discovery \Api \Discovery ;
8
+
9
+
10
+ /**
11
+ * @author Tobias Nyholm <[email protected] >
12
+ */
13
+ class HttplugFactoryTest extends \PHPUnit_Framework_TestCase
14
+ {
15
+ public function testEvaluateCondition ()
16
+ {
17
+ $ method = new \ReflectionMethod (HttplugFactory::class, 'evaluateCondition ' );
18
+ $ method ->setAccessible (true );
19
+ $ factory = new HttplugFactory ($ this ->getMock (Discovery::class));
20
+ $ existingClass = MessageJournal::class;
21
+
22
+ // String
23
+ $ result = $ method ->invoke ($ factory , $ existingClass );
24
+ $ this ->assertTrue ($ result );
25
+ $ result = $ method ->invoke ($ factory , 'non_existent_class ' );
26
+ $ this ->assertFalse ($ result );
27
+
28
+ // Callable
29
+ $ result = $ method ->invoke ($ factory , function () {return 'value ' ;});
30
+ $ this ->assertEquals ('value ' , $ result );
31
+
32
+ // Boolean
33
+ $ result = $ method ->invoke ($ factory , true );
34
+ $ this ->assertTrue ($ result );
35
+ $ result = $ method ->invoke ($ factory , false );
36
+ $ this ->assertFalse ($ result );
37
+
38
+ // Array
39
+ $ result = $ method ->invoke ($ factory , [true , $ existingClass ]);
40
+ $ this ->assertTrue ((bool ) $ result );
41
+ $ result = $ method ->invoke ($ factory , [true , $ existingClass , false ]);
42
+ $ this ->assertFalse ((bool ) $ result );
43
+
44
+ // Associative array
45
+ $ result = $ method ->invoke ($ factory , ['test1 ' =>true , $ existingClass ]);
46
+ $ this ->assertTrue ((bool ) $ result );
47
+
48
+ }
49
+ }
0 commit comments