Completed
Pull Request — master (#61)
by
unknown
02:02
created

BundleMetadataTest::testCustomNamespace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 7.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Sonata\EasyExtendsBundle\Tests\Bundle;
4
5
// Unfortunately phpunit cannot mock a class in chosen namespace.
6
// Therefore mocks are stored in Fixtures/bundle1 directory and required here.
7
require_once __DIR__.'/Fixtures/bundle1/SonataAcmeBundle.php';
8
require_once __DIR__.'/Fixtures/bundle1/SonataNotExtendableBundle.php';
9
require_once __DIR__.'/Fixtures/bundle1/SymfonyNotExtendableBundle.php';
10
require_once __DIR__.'/Fixtures/bundle1/LongNamespaceBundle.php';
11
require_once __DIR__.'/Fixtures/bundle1/AcmeBundle.php';
12
13
use Sonata\EasyExtendsBundle\Bundle\BundleMetadata;
14
15
class BundleMetadataTest extends \PHPUnit_Framework_TestCase
16
{
17
    public function testBundleMetadata()
18
    {
19
        $bundle = new \Sonata\AcmeBundle\SonataAcmeBundle();
20
21
        $bundleMetadata = new BundleMetadata($bundle, array('application_dir' => 'app/Application/:vendor', 'namespace' => 'Application\\:vendor'));
22
23
        $this->assertTrue($bundleMetadata->isExtendable());
24
        $this->assertTrue($bundleMetadata->isValid());
25
        $this->assertEquals('SonataAcmeBundle', $bundleMetadata->getName());
26
        $this->assertEquals('Sonata', $bundleMetadata->getVendor());
27
        $this->assertEquals('Sonata\AcmeBundle', $bundleMetadata->getNamespace());
28
        $this->assertEquals('app/Application/Sonata/AcmeBundle', $bundleMetadata->getExtendedDirectory());
29
        $this->assertEquals('Application\Sonata\AcmeBundle', $bundleMetadata->getExtendedNamespace());
30
        $this->assertInstanceOf('Sonata\EasyExtendsBundle\Bundle\OrmMetadata', $bundleMetadata->getOrmMetadata());
31
        $this->assertInstanceOf('Sonata\EasyExtendsBundle\Bundle\OdmMetadata', $bundleMetadata->getOdmMetadata());
32
        $this->assertSame($bundle, $bundleMetadata->getBundle());
33
    }
34
35
    public function testCustomNamespace()
36
    {
37
        $bundle = new \Sonata\AcmeBundle\SonataAcmeBundle();
38
39
        $bundleMetadata = new BundleMetadata($bundle, array('application_dir' => 'app/Custom/:vendor', 'namespace' => 'Custom\\:vendor'));
40
41
        $this->assertEquals('app/Custom/Sonata/AcmeBundle', $bundleMetadata->getExtendedDirectory());
42
        $this->assertEquals('Custom\Sonata\AcmeBundle', $bundleMetadata->getExtendedNamespace());
43
    }
44
45
    public function testApplicationNotExtendableBundle()
46
    {
47
        $bundle = new \Application\Sonata\NotExtendableBundle();
48
49
        $bundleMetadata = new BundleMetadata($bundle, array('application_dir' => 'Application', 'namespace' => 'Application'));
50
51
        $this->assertFalse($bundleMetadata->isValid());
52
        $this->assertFalse($bundleMetadata->isExtendable());
53
    }
54
55
    public function testSymfonyNotExtendableBundle()
56
    {
57
        $bundle = new \Symfony\Bundle\NotExtendableBundle();
58
59
        $bundleMetadata = new BundleMetadata($bundle, array('application_dir' => 'Application', 'namespace' => 'Application'));
60
61
        $this->assertFalse($bundleMetadata->isValid());
62
        $this->assertFalse($bundleMetadata->isExtendable());
63
    }
64
65
    public function testBundleNamespace()
66
    {
67
        $bundle = new \Sonata\Bundle\AcmeBundle\LongNamespaceBundle();
68
69
        $bundleMetadata = new BundleMetadata($bundle, array('application_dir' => 'Application', 'namespace' => 'Application'));
70
71
        $this->assertFalse($bundleMetadata->isValid());
72
    }
73
74
    public function testBundleName()
75
    {
76
        $bundle = new \Sonata\AcmeBundle\AcmeBundle();
77
78
        $bundleMetadata = new BundleMetadata($bundle, array('application_dir' => 'Application', 'namespace' => 'Application'));
79
80
        $this->assertFalse($bundleMetadata->isValid());
81
    }
82
}
83