@@ 21-117 (lines=97) @@ | ||
18 | * @package PhpSchool\LearnYouPhpTest\Exercise |
|
19 | * @author Michael Woodward <[email protected]> |
|
20 | */ |
|
21 | class ArrayWeGoTest extends PHPUnit_Framework_TestCase |
|
22 | { |
|
23 | ||
24 | /** |
|
25 | * @var Generator |
|
26 | */ |
|
27 | private $faker; |
|
28 | ||
29 | /** |
|
30 | * @var Filesystem |
|
31 | */ |
|
32 | private $filesystem; |
|
33 | ||
34 | public function setUp() |
|
35 | { |
|
36 | $this->faker = Factory::create(); |
|
37 | $this->filesystem = new Filesystem; |
|
38 | } |
|
39 | ||
40 | public function testArrWeGoExercise() |
|
41 | { |
|
42 | $e = new ArrayWeGo($this->filesystem, $this->faker); |
|
43 | $this->assertEquals('Array We Go!', $e->getName()); |
|
44 | $this->assertEquals('Filter an array of file paths and map to SplFile objects', $e->getDescription()); |
|
45 | $this->assertEquals(ExerciseType::CLI, $e->getType()); |
|
46 | ||
47 | $this->assertInstanceOf(SolutionInterface::class, $e->getSolution()); |
|
48 | $this->assertFileExists(realpath($e->getProblem())); |
|
49 | $this->assertNull($e->tearDown()); |
|
50 | } |
|
51 | ||
52 | public function testGetArgsCreateAtLeastOneExistingFile() |
|
53 | { |
|
54 | $e = new ArrayWeGo($this->filesystem, $this->faker); |
|
55 | $args = $e->getArgs(); |
|
56 | ||
57 | $existingFiles = array_filter($args, 'file_exists'); |
|
58 | ||
59 | foreach ($existingFiles as $file) { |
|
60 | $this->assertFileExists($file); |
|
61 | } |
|
62 | ||
63 | $this->assertGreaterThanOrEqual(1, count($existingFiles)); |
|
64 | } |
|
65 | ||
66 | public function testGetArgsHasAtLeastOneNonExistingFile() |
|
67 | { |
|
68 | $e = new ArrayWeGo($this->filesystem, $this->faker); |
|
69 | $args = $e->getArgs(); |
|
70 | ||
71 | $nonExistingFiles = array_filter($args, function ($arg) { |
|
72 | return !file_exists($arg); |
|
73 | }); |
|
74 | ||
75 | foreach ($nonExistingFiles as $file) { |
|
76 | $this->assertFileNotExists($file); |
|
77 | } |
|
78 | ||
79 | $this->assertGreaterThanOrEqual(1, count($nonExistingFiles)); |
|
80 | } |
|
81 | ||
82 | public function testTearDownRemovesFile() |
|
83 | { |
|
84 | $e = new ArrayWeGo($this->filesystem, $this->faker); |
|
85 | $args = $e->getArgs(); |
|
86 | ||
87 | $existingFiles = array_filter($args, 'file_exists'); |
|
88 | ||
89 | $this->assertFileExists($existingFiles[0]); |
|
90 | ||
91 | $e->tearDown(); |
|
92 | ||
93 | $this->assertFileNotExists($existingFiles[0]); |
|
94 | } |
|
95 | ||
96 | public function testFunctionRequirements() |
|
97 | { |
|
98 | $e = new ArrayWeGo($this->filesystem, $this->faker); |
|
99 | $this->assertEquals(['array_shift', 'array_filter', 'array_map'], $e->getRequiredFunctions()); |
|
100 | $this->assertEquals(['basename'], $e->getBannedFunctions()); |
|
101 | } |
|
102 | ||
103 | public function testConfigure() |
|
104 | { |
|
105 | $dispatcher = $this->getMockBuilder(ExerciseDispatcher::class) |
|
106 | ->disableOriginalConstructor() |
|
107 | ->getMock(); |
|
108 | ||
109 | $dispatcher |
|
110 | ->expects($this->once()) |
|
111 | ->method('requireCheck') |
|
112 | ->with(FunctionRequirementsCheck::class); |
|
113 | ||
114 | $e = new ArrayWeGo($this->filesystem, $this->faker); |
|
115 | $e->configure($dispatcher); |
|
116 | } |
|
117 | } |
|
118 |
@@ 22-118 (lines=97) @@ | ||
19 | * @package PhpSchool\LearnYouPhpTest\Exercise |
|
20 | * @author Michael Woodward <[email protected]> |
|
21 | */ |
|
22 | class ExceptionalCodingTest extends PHPUnit_Framework_TestCase |
|
23 | { |
|
24 | ||
25 | /** |
|
26 | * @var Generator |
|
27 | */ |
|
28 | private $faker; |
|
29 | ||
30 | /** |
|
31 | * @var Filesystem |
|
32 | */ |
|
33 | private $filesystem; |
|
34 | ||
35 | public function setUp() |
|
36 | { |
|
37 | $this->faker = Factory::create(); |
|
38 | $this->filesystem = new Filesystem; |
|
39 | } |
|
40 | ||
41 | public function testArrWeGoExercise() |
|
42 | { |
|
43 | $e = new ExceptionalCoding($this->filesystem, $this->faker); |
|
44 | $this->assertEquals('Exceptional Coding', $e->getName()); |
|
45 | $this->assertEquals('Introduction to Exceptions', $e->getDescription()); |
|
46 | $this->assertEquals(ExerciseType::CLI, $e->getType()); |
|
47 | ||
48 | $this->assertInstanceOf(SolutionInterface::class, $e->getSolution()); |
|
49 | $this->assertFileExists(realpath($e->getProblem())); |
|
50 | $this->assertNull($e->tearDown()); |
|
51 | } |
|
52 | ||
53 | public function testGetArgsCreateAtleastOneExistingFile() |
|
54 | { |
|
55 | $e = new ExceptionalCoding($this->filesystem, $this->faker); |
|
56 | $args = $e->getArgs(); |
|
57 | ||
58 | $existingFiles = array_filter($args, 'file_exists'); |
|
59 | ||
60 | foreach ($existingFiles as $file) { |
|
61 | $this->assertFileExists($file); |
|
62 | } |
|
63 | ||
64 | $this->assertGreaterThanOrEqual(1, count($existingFiles)); |
|
65 | } |
|
66 | ||
67 | public function testGetArgsHasAtleastOneNonExistingFile() |
|
68 | { |
|
69 | $e = new ExceptionalCoding($this->filesystem, $this->faker); |
|
70 | $args = $e->getArgs(); |
|
71 | ||
72 | $nonExistingFiles = array_filter($args, function ($arg) { |
|
73 | return !file_exists($arg); |
|
74 | }); |
|
75 | ||
76 | foreach ($nonExistingFiles as $file) { |
|
77 | $this->assertFileNotExists($file); |
|
78 | } |
|
79 | ||
80 | $this->assertGreaterThanOrEqual(1, count($nonExistingFiles)); |
|
81 | } |
|
82 | ||
83 | public function testTearDownRemovesFile() |
|
84 | { |
|
85 | $e = new ExceptionalCoding($this->filesystem, $this->faker); |
|
86 | $args = $e->getArgs(); |
|
87 | ||
88 | $existingFiles = array_filter($args, 'file_exists'); |
|
89 | ||
90 | $this->assertFileExists($existingFiles[0]); |
|
91 | ||
92 | $e->tearDown(); |
|
93 | ||
94 | $this->assertFileNotExists($existingFiles[0]); |
|
95 | } |
|
96 | ||
97 | public function testFunctionRequirements() |
|
98 | { |
|
99 | $e = new ExceptionalCoding($this->filesystem, $this->faker); |
|
100 | $this->assertEquals([], $e->getRequiredFunctions()); |
|
101 | $this->assertEquals(['array_filter', 'file_exists'], $e->getBannedFunctions()); |
|
102 | } |
|
103 | ||
104 | public function testConfigure() |
|
105 | { |
|
106 | $dispatcher = $this->getMockBuilder(ExerciseDispatcher::class) |
|
107 | ->disableOriginalConstructor() |
|
108 | ->getMock(); |
|
109 | ||
110 | $dispatcher |
|
111 | ->expects($this->once()) |
|
112 | ->method('requireCheck') |
|
113 | ->with(FunctionRequirementsCheck::class); |
|
114 | ||
115 | $e = new ExceptionalCoding($this->filesystem, $this->faker); |
|
116 | $e->configure($dispatcher); |
|
117 | } |
|
118 | } |
|
119 |