File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111
1212namespace Plum \PlumJson ;
1313
14+ use ArrayIterator ;
1415use Braincrafted \Json \Json ;
1516use Plum \Plum \Reader \ReaderInterface ;
1617
@@ -38,11 +39,11 @@ public function __construct($fileName)
3839 }
3940
4041 /**
41- * @return \ ArrayIterator
42+ * @return ArrayIterator
4243 */
4344 public function getIterator ()
4445 {
45- return new \ ArrayIterator ($ this ->getJson ());
46+ return new ArrayIterator ($ this ->getJson ());
4647 }
4748
4849 /**
@@ -66,4 +67,14 @@ protected function getJson()
6667
6768 return $ this ->data ;
6869 }
70+
71+ /**
72+ * @param mixed $input
73+ *
74+ * @return bool
75+ */
76+ public static function accepts ($ input )
77+ {
78+ return is_string ($ input ) && preg_match ('/\.json$/ ' , $ input );
79+ }
6980}
Original file line number Diff line number Diff line change 1111
1212namespace Plum \PlumJson ;
1313
14+ use ArrayIterator ;
1415use Braincrafted \Json \Json ;
1516use Plum \Plum \Reader \ReaderInterface ;
1617
@@ -38,11 +39,11 @@ public function __construct($json)
3839 }
3940
4041 /**
41- * @return \ ArrayIterator
42+ * @return ArrayIterator
4243 */
4344 public function getIterator ()
4445 {
45- return new \ ArrayIterator ($ this ->getJson ());
46+ return new ArrayIterator ($ this ->getJson ());
4647 }
4748
4849 /**
@@ -66,4 +67,14 @@ protected function getJson()
6667
6768 return $ this ->data ;
6869 }
70+
71+ /**
72+ * @param mixed $input
73+ *
74+ * @return bool
75+ */
76+ public static function accepts ($ input )
77+ {
78+ return is_array ($ input );
79+ }
6980}
Original file line number Diff line number Diff line change @@ -55,4 +55,23 @@ public function countReturnsNumberOfItemsInJsonFile()
5555
5656 $ this ->assertEquals (1 , $ reader ->count ());
5757 }
58+
59+ /**
60+ * @test
61+ * @covers Plum\PlumJson\JsonFileReader::accepts()
62+ */
63+ public function acceptsReturnsTrueIfInputIsJsonFile ()
64+ {
65+ $ this ->assertTrue (JsonFileReader::accepts ('foo.json ' ));
66+ }
67+
68+ /**
69+ * @test
70+ * @covers Plum\PlumJson\JsonFileReader::accepts()
71+ */
72+ public function acceptsReturnsFalseIfInputIsNotJsonFile ()
73+ {
74+ $ this ->assertFalse (JsonFileReader::accepts ('foo.csv ' ));
75+ $ this ->assertFalse (JsonFileReader::accepts ([]));
76+ }
5877}
Original file line number Diff line number Diff line change @@ -45,4 +45,22 @@ public function countReturnsNumberOfItemsInJsonFile()
4545
4646 $ this ->assertEquals (1 , $ reader ->count ());
4747 }
48+
49+ /**
50+ * @test
51+ * @covers Plum\PlumJson\JsonReader::accepts()
52+ */
53+ public function acceptsReturnsTrueIfInputIsArray ()
54+ {
55+ $ this ->assertTrue (JsonReader::accepts (['foo ' ]));
56+ }
57+
58+ /**
59+ * @test
60+ * @covers Plum\PlumJson\JsonReader::accepts()
61+ */
62+ public function acceptsReturnsFalseIfInputIsNotArray ()
63+ {
64+ $ this ->assertFalse (JsonReader::accepts ('foo ' ));
65+ }
4866}
You can’t perform that action at this time.
0 commit comments