Completed
Pull Request — 2.x (#165)
by
unknown
01:35
created

BundleMetadataTest::testWithNamespacePrefix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 1
eloc 13
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 25 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 PHPUnit\Framework\TestCase;
23
use Sonata\EasyExtendsBundle\Bundle\BundleMetadata;
24
25
class BundleMetadataTest extends TestCase
26
{
27
    public function testBundleMetadata()
28
    {
29
        $bundle = new \Sonata\AcmeBundle\SonataAcmeBundle();
30
31
        $bundleMetadata = new BundleMetadata($bundle, [
32
            'application_dir' => 'app/Application/:vendor',
33
            'namespace' => 'Application\\:vendor',
34
            'namespace_prefix' => '',
35
        ]);
36
37
        $this->assertTrue($bundleMetadata->isExtendable());
38
        $this->assertTrue($bundleMetadata->isValid());
39
        $this->assertEquals('SonataAcmeBundle', $bundleMetadata->getName());
40
        $this->assertEquals('Sonata', $bundleMetadata->getVendor());
41
        $this->assertEquals('Sonata\AcmeBundle', $bundleMetadata->getNamespace());
42
        $this->assertEquals('app/Application/Sonata/AcmeBundle', $bundleMetadata->getExtendedDirectory());
43
        $this->assertEquals('Application\Sonata\AcmeBundle', $bundleMetadata->getExtendedNamespace());
44
        $this->assertInstanceOf('Sonata\EasyExtendsBundle\Bundle\OrmMetadata', $bundleMetadata->getOrmMetadata());
45
        $this->assertInstanceOf('Sonata\EasyExtendsBundle\Bundle\OdmMetadata', $bundleMetadata->getOdmMetadata());
46
        $this->assertSame($bundle, $bundleMetadata->getBundle());
47
    }
48
49
    public function testCustomNamespace()
50
    {
51
        $bundle = new \Sonata\AcmeBundle\SonataAcmeBundle();
52
53
        $bundleMetadata = new BundleMetadata($bundle, [
54
            'application_dir' => 'app/Custom/:vendor',
55
            'namespace' => 'Custom\\:vendor',
56
            'namespace_prefix' => '',
57
        ]);
58
59
        $this->assertEquals('app/Custom/Sonata/AcmeBundle', $bundleMetadata->getExtendedDirectory());
60
        $this->assertEquals('Custom\Sonata\AcmeBundle', $bundleMetadata->getExtendedNamespace());
61
    }
62
63
    public function testApplicationNotExtendableBundle()
64
    {
65
        $bundle = new \Application\Sonata\NotExtendableBundle();
66
67
        $bundleMetadata = new BundleMetadata($bundle, [
68
            'application_dir' => 'Application',
69
            'namespace' => 'Application',
70
            'namespace_prefix' => '',
71
        ]);
72
73
        $this->assertFalse($bundleMetadata->isValid());
74
        $this->assertFalse($bundleMetadata->isExtendable());
75
    }
76
77
    public function testSymfonyNotExtendableBundle()
78
    {
79
        $bundle = new \Symfony\Bundle\NotExtendableBundle();
80
81
        $bundleMetadata = new BundleMetadata($bundle, [
82
            'application_dir' => 'Application',
83
            'namespace' => 'Application',
84
            'namespace_prefix' => '',
85
        ]);
86
87
        $this->assertFalse($bundleMetadata->isValid());
88
        $this->assertFalse($bundleMetadata->isExtendable());
89
    }
90
91
    public function testBundleNamespace()
92
    {
93
        $bundle = new \Sonata\Bundle\AcmeBundle\LongNamespaceBundle();
94
95
        $bundleMetadata = new BundleMetadata($bundle, [
96
            'application_dir' => 'Application',
97
            'namespace' => 'Application',
98
            'namespace_prefix' => '',
99
        ]);
100
101
        $this->assertFalse($bundleMetadata->isValid());
102
    }
103
104
    public function testBundleName()
105
    {
106
        $bundle = new \Sonata\AcmeBundle\AcmeBundle();
107
108
        $bundleMetadata = new BundleMetadata($bundle, [
109
            'application_dir' => 'Application',
110
            'namespace' => 'Application',
111
            'namespace_prefix' => '',
112
        ]);
113
114
        $this->assertFalse($bundleMetadata->isValid());
115
    }
116
117
    public function testWithNamespacePrefix()
118
    {
119
        $bundle = new \Sonata\AcmeBundle\SonataAcmeBundle();
120
121
        $bundleMetadata = new BundleMetadata($bundle, [
122
            'application_dir' => 'src/Application/:vendor',
123
            'namespace' => 'Application\\:vendor',
124
            'namespace_prefix' => 'App\\',
125
        ]);
126
127
        $this->assertEquals('SonataAcmeBundle', $bundleMetadata->getName());
128
        $this->assertEquals('Sonata', $bundleMetadata->getVendor());
129
        $this->assertEquals('Application', $bundleMetadata->getApplication());
130
        $this->assertEquals('Sonata\AcmeBundle', $bundleMetadata->getNamespace());
131
        $this->assertEquals('src/Application/Sonata/AcmeBundle', $bundleMetadata->getExtendedDirectory());
132
        $this->assertEquals('App\Application\Sonata\AcmeBundle', $bundleMetadata->getExtendedNamespace());
133
        $this->assertSame($bundle, $bundleMetadata->getBundle());
134
    }
135
}
136