Completed
Push — master ( b0dd07...48a5d3 )
by Aydin
02:14
created

testGetRequestsReturnsMultipleRequestsForEachEndpoint()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4286
cc 2
eloc 9
nc 2
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\Solution\SolutionInterface;
9
use PHPUnit_Framework_TestCase;
10
use Psr\Http\Message\RequestInterface;
11
12
/**
13
 * Class DependencyHeavenTest
14
 * @package PhpSchool\LearnYouPhpTest\Exercise
15
 * @author Michael Woodward <[email protected]>
16
 */
17
class DependencyHeavenTest extends PHPUnit_Framework_TestCase
18
{
19
20
    /**
21
     * @var Generator
22
     */
23
    private $faker;
24
25
    public function setUp()
26
    {
27
        $this->faker = Factory::create('Fr_fr');
28
    }
29
30 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...
31
    {
32
        $e = new DependencyHeaven($this->faker);
33
34
        $this->assertEquals('Dependency Heaven', $e->getName());
35
        $this->assertEquals('An introduction to Composer dependency management', $e->getDescription());
36
37
        $this->assertInstanceOf(SolutionInterface::class, $e->getSolution());
38
        $this->assertFileExists(realpath($e->getSolution()->getEntryPoint()));
39
        $this->assertFileExists(realpath($e->getProblem()));
40
        $this->assertNull($e->tearDown());
41
    }
42
43
    public function testGetRequiredPackages()
44
    {
45
        $this->assertSame(
46
            ['klein/klein', 'danielstjules/stringy'],
47
            (new DependencyHeaven($this->faker))->getRequiredPackages()
48
        );
49
    }
50
51
    public function testGetRequests()
52
    {
53
        $e = new DependencyHeaven($this->faker);
54
55
        $requests  = $e->getRequests();
56
57
        foreach ($requests as $request) {
58
            $this->assertInstanceOf(RequestInterface::class, $request);
59
            $this->assertSame('POST', $request->getMethod());
60
            $this->assertSame(['application/x-www-form-urlencoded'], $request->getHeader('Content-Type'));
61
            $this->assertNotEmpty($request->getBody());
62
        }
63
    }
64
65
    public function testGetRequestsReturnsMultipleRequestsForEachEndpoint()
66
    {
67
        $e = new DependencyHeaven($this->faker);
68
69
        $endPoints = array_map(function (RequestInterface $request) {
70
            return $request->getUri()->getPath();
71
        }, $e->getRequests());
72
73
        $counts = array_count_values($endPoints);
74
        foreach (['/reverse', '/swapcase', '/titleize'] as $endPoint) {
75
            $this->assertTrue(isset($counts[$endPoint]));
76
            $this->assertGreaterThan(1, $counts[$endPoint]);
77
        }
78
    }
79
}
80