Completed
Push — master ( 48a5d3...028360 )
by Aydin
03:14
created

ArrayWeGoTest::testConfigure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 14
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 14
loc 14
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
4
namespace PhpSchool\LearnYouPhpTest\Exercise;
5
6
use Faker\Factory;
7
use Faker\Generator;
8
use PhpSchool\LearnYouPhp\Exercise\ArrayWeGo;
9
use PhpSchool\PhpWorkshop\Check\FunctionRequirementsCheck;
10
use PhpSchool\PhpWorkshop\Exercise\ExerciseType;
11
use PhpSchool\PhpWorkshop\ExerciseDispatcher;
12
use PhpSchool\PhpWorkshop\Solution\SolutionInterface;
13
use PHPUnit_Framework_TestCase;
14
use Symfony\Component\Filesystem\Filesystem;
15
16
/**
17
 * Class ArrayWeGoTest
18
 * @package PhpSchool\LearnYouPhpTest\Exercise
19
 * @author Michael Woodward <[email protected]>
20
 */
21 View Code Duplication
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