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

DependencyHeavenTest::testConfigure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace PhpSchool\LearnYouPhpTest\Exercise;
4
5
use Faker\Factory;
6
use Faker\Generator;
7
use PhpSchool\LearnYouPhp\Exercise\DependencyHeaven;
8
use PhpSchool\PhpWorkshop\Check\ComposerCheck;
9
use PhpSchool\PhpWorkshop\Exercise\ExerciseType;
10
use PhpSchool\PhpWorkshop\ExerciseDispatcher;
11
use PhpSchool\PhpWorkshop\Solution\SolutionInterface;
12
use PHPUnit_Framework_TestCase;
13
use Psr\Http\Message\RequestInterface;
14
15
/**
16
 * Class DependencyHeavenTest
17
 * @package PhpSchool\LearnYouPhpTest\Exercise
18
 * @author Michael Woodward <[email protected]>
19
 */
20
class DependencyHeavenTest extends PHPUnit_Framework_TestCase
21
{
22
23
    /**
24
     * @var Generator
25
     */
26
    private $faker;
27
28
    public function setUp()
29
    {
30
        $this->faker = Factory::create('Fr_fr');
31
    }
32
33 View Code Duplication
    public function testDependencyHeavenExercise()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        $e = new DependencyHeaven($this->faker);
36
        $this->assertEquals('Dependency Heaven', $e->getName());
37
        $this->assertEquals('An introduction to Composer dependency management', $e->getDescription());
38
        $this->assertEquals(ExerciseType::CGI, $e->getType());
39
40
        $this->assertInstanceOf(SolutionInterface::class, $e->getSolution());
41
        $this->assertFileExists(realpath($e->getSolution()->getEntryPoint()));
42
        $this->assertFileExists(realpath($e->getProblem()));
43
        $this->assertNull($e->tearDown());
44
    }
45
46
    public function testGetRequiredPackages()
47
    {
48
        $this->assertSame(
49
            ['klein/klein', 'danielstjules/stringy'],
50
            (new DependencyHeaven($this->faker))->getRequiredPackages()
51
        );
52
    }
53
54
    public function testGetRequests()
55
    {
56
        $e = new DependencyHeaven($this->faker);
57
58
        $requests  = $e->getRequests();
59
60
        foreach ($requests as $request) {
61
            $this->assertInstanceOf(RequestInterface::class, $request);
62
            $this->assertSame('POST', $request->getMethod());
63
            $this->assertSame(['application/x-www-form-urlencoded'], $request->getHeader('Content-Type'));
64
            $this->assertNotEmpty($request->getBody());
65
        }
66
    }
67
68
    public function testGetRequestsReturnsMultipleRequestsForEachEndpoint()
69
    {
70
        $e = new DependencyHeaven($this->faker);
71
72
        $endPoints = array_map(function (RequestInterface $request) {
73
            return $request->getUri()->getPath();
74
        }, $e->getRequests());
75
76
        $counts = array_count_values($endPoints);
77
        foreach (['/reverse', '/swapcase', '/titleize'] as $endPoint) {
78
            $this->assertTrue(isset($counts[$endPoint]));
79
            $this->assertGreaterThan(1, $counts[$endPoint]);
80
        }
81
    }
82
83
    public function testConfigure()
84
    {
85
        $dispatcher = $this->getMockBuilder(ExerciseDispatcher::class)
86
            ->disableOriginalConstructor()
87
            ->getMock();
88
89
        $dispatcher
90
            ->expects($this->once())
91
            ->method('requireCheck')
92
            ->with(ComposerCheck::class);
93
94
        $e = new DependencyHeaven($this->faker);
95
        $e->configure($dispatcher);
96
    }
97
}
98