Completed
Pull Request — 2.x (#80)
by Christian
02:38 queued 10s
created

BundleMetadataTest::testBundleName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 11
rs 9.4285
cc 1
eloc 6
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 24 and the first side effect is on line 16.

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
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\EasyExtendsBundle\Tests\Bundle;
13
14
// Unfortunately phpunit cannot mock a class in chosen namespace.
15
// Therefore mocks are stored in Fixtures/bundle1 directory and required here.
16
require_once __DIR__.'/Fixtures/bundle1/SonataAcmeBundle.php';
17
require_once __DIR__.'/Fixtures/bundle1/SonataNotExtendableBundle.php';
18
require_once __DIR__.'/Fixtures/bundle1/SymfonyNotExtendableBundle.php';
19
require_once __DIR__.'/Fixtures/bundle1/LongNamespaceBundle.php';
20
require_once __DIR__.'/Fixtures/bundle1/AcmeBundle.php';
21
22
use Sonata\EasyExtendsBundle\Bundle\BundleMetadata;
23
24
class BundleMetadataTest extends \PHPUnit_Framework_TestCase
25
{
26
    public function testBundleMetadata()
27
    {
28
        $bundle = new \Sonata\AcmeBundle\SonataAcmeBundle();
29
30
        $bundleMetadata = new BundleMetadata($bundle, array(
31
            'application_dir' => 'app/Application/:vendor',
32
            'namespace' => 'Application\\:vendor',
33
        ));
34
35
        $this->assertTrue($bundleMetadata->isExtendable());
36
        $this->assertTrue($bundleMetadata->isValid());
37
        $this->assertEquals('SonataAcmeBundle', $bundleMetadata->getName());
38
        $this->assertEquals('Sonata', $bundleMetadata->getVendor());
39
        $this->assertEquals('Sonata\AcmeBundle', $bundleMetadata->getNamespace());
40
        $this->assertEquals('app/Application/Sonata/AcmeBundle', $bundleMetadata->getExtendedDirectory());
41
        $this->assertEquals('Application\Sonata\AcmeBundle', $bundleMetadata->getExtendedNamespace());
42
        $this->assertInstanceOf('Sonata\EasyExtendsBundle\Bundle\OrmMetadata', $bundleMetadata->getOrmMetadata());
43
        $this->assertInstanceOf('Sonata\EasyExtendsBundle\Bundle\OdmMetadata', $bundleMetadata->getOdmMetadata());
44
        $this->assertSame($bundle, $bundleMetadata->getBundle());
45
    }
46
47
    public function testCustomNamespace()
48
    {
49
        $bundle = new \Sonata\AcmeBundle\SonataAcmeBundle();
50
51
        $bundleMetadata = new BundleMetadata($bundle, array(
52
            'application_dir' => 'app/Custom/:vendor',
53
            'namespace' => 'Custom\\:vendor',
54
        ));
55
56
        $this->assertEquals('app/Custom/Sonata/AcmeBundle', $bundleMetadata->getExtendedDirectory());
57
        $this->assertEquals('Custom\Sonata\AcmeBundle', $bundleMetadata->getExtendedNamespace());
58
    }
59
60
    public function testApplicationNotExtendableBundle()
61
    {
62
        $bundle = new \Application\Sonata\NotExtendableBundle();
63
64
        $bundleMetadata = new BundleMetadata($bundle, array(
65
            'application_dir' => 'Application',
66
            'namespace' => 'Application',
67
        ));
68
69
        $this->assertFalse($bundleMetadata->isValid());
70
        $this->assertFalse($bundleMetadata->isExtendable());
71
    }
72
73
    public function testSymfonyNotExtendableBundle()
74
    {
75
        $bundle = new \Symfony\Bundle\NotExtendableBundle();
76
77
        $bundleMetadata = new BundleMetadata($bundle, array(
78
            'application_dir' => 'Application',
79
            'namespace' => 'Application',
80
        ));
81
82
        $this->assertFalse($bundleMetadata->isValid());
83
        $this->assertFalse($bundleMetadata->isExtendable());
84
    }
85
86
    public function testBundleNamespace()
87
    {
88
        $bundle = new \Sonata\Bundle\AcmeBundle\LongNamespaceBundle();
89
90
        $bundleMetadata = new BundleMetadata($bundle, array(
91
            'application_dir' => 'Application',
92
            'namespace' => 'Application',
93
        ));
94
95
        $this->assertFalse($bundleMetadata->isValid());
96
    }
97
98
    public function testBundleName()
99
    {
100
        $bundle = new \Sonata\AcmeBundle\AcmeBundle();
101
102
        $bundleMetadata = new BundleMetadata($bundle, array(
103
            'application_dir' => 'Application',
104
            'namespace' => 'Application',
105
        ));
106
107
        $this->assertFalse($bundleMetadata->isValid());
108
    }
109
}
110