Completed
Push — master ( a2d301...031f19 )
by John
02:35
created

DocumentRepositoryTest::willCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the KleijnWeb\SwaggerBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\SwaggerBundle\Tests\Document;
10
11
use KleijnWeb\SwaggerBundle\Document\DocumentRepository;
12
13
/**
14
 * @author John Kleijn <[email protected]>
15
 */
16
class DocumentRepositoryTest extends \PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * @var DocumentRepository
20
     */
21
    private $repository;
22
23
    protected function setUp()
24
    {
25
        $this->repository = new DocumentRepository();
26
    }
27
28
    /**
29
     * @test
30
     * @expectedException \InvalidArgumentException
31
     */
32
    public function willFailWhenKeyIsEmpty()
33
    {
34
        $this->repository->get('');
35
    }
36
37
    /**
38
     * @test
39
     * @expectedException \KleijnWeb\SwaggerBundle\Document\Exception\ResourceNotReadableException
40
     */
41
    public function willFailWhenPathDoesNotExist()
42
    {
43
        $this->repository->get('/this/is/total/bogus');
44
    }
45
46
    /**
47
     * @test
48
     */
49
    public function gettingDocumentThatDoestExistWillConstructIt()
50
    {
51
        $document = $this->repository->get('src/Tests/Functional/PetStore/app/swagger/petstore.yml');
52
        $this->assertInstanceOf('KleijnWeb\SwaggerBundle\Document\SwaggerDocument', $document);
53
    }
54
55
    /**
56
     * @test
57
     */
58
    public function definitionIsObject()
59
    {
60
        $document = $this->repository->get('src/Tests/Functional/PetStore/app/swagger/petstore.yml');
61
        $this->assertInternalType('object', $document->getDefinition());
62
    }
63
64
    /**
65
     * @test
66
     */
67
    public function willCache()
68
    {
69
        $path = 'src/Tests/Functional/PetStore/app/swagger/petstore.yml';
70
        $cache = $this->getMockBuilder('Doctrine\Common\Cache\ArrayCache')->disableOriginalConstructor()->getMock();
71
        $repository = new DocumentRepository(null, $cache);
72
        $cache->expects($this->exactly(1))->method('fetch')->with($path);
73
        $cache->expects($this->exactly(1))->method('save')->with($path, $this->isType('object'));
74
        $document = $repository->get($path);
75
        $this->assertInternalType('object', $document->getDefinition());
76
    }
77
78
    /**
79
     * @test
80
     */
81
    public function canUsePathPrefix()
82
    {
83
        $this->repository = new DocumentRepository('src/Tests/Functional/PetStore');
84
        $document = $this->repository->get('app/swagger/petstore.yml');
85
        $this->assertInstanceOf('KleijnWeb\SwaggerBundle\Document\SwaggerDocument', $document);
86
    }
87
}
88