Skip to content

Commit 08b548f

Browse files
committed
Add base bundle structure.
1 parent 620cf1a commit 08b548f

12 files changed

+452
-5
lines changed

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@
4141
"autoload": {
4242
"psr-4": {
4343
"MetaModels\\AttributeSelectBundle\\": "src"
44-
}
44+
},
45+
"files": [
46+
"src/deprecated-autoload.php"
47+
]
4548
},
4649
"autoload-dev": {
4750
"psr-4": {

phpunit.xml.dist

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
>
1313
<testsuites>
1414
<testsuite name="MetaModels attribute select tests">
15-
<directory>./tests/MetaModels/</directory>
15+
<directory>./tests/</directory>
1616
</testsuite>
1717
</testsuites>
1818

@@ -24,7 +24,7 @@
2424

2525
<filter>
2626
<whitelist>
27-
<directory>./src/system/modules/metamodelsattribute_select/MetaModels/</directory>
27+
<directory>./src/</directory>
2828
</whitelist>
2929
</filter>
3030
</phpunit>

src/ContaoManager/Plugin.php

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/**
4+
* * This file is part of MetaModels/attribute_select.
5+
*
6+
* (c) 2012-2017 The MetaModels team.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* This project is provided in good faith and hope to be usable by anyone.
12+
*
13+
* @package MetaModels
14+
* @subpackage AttributeSelect
15+
* @author David Molineus <[email protected]>
16+
* @copyright 2012-2017 The MetaModels team.
17+
* @license https://github.com/MetaModels/attribute_text/blob/master/LICENSE LGPL-3.0
18+
* @filesource
19+
*/
20+
21+
namespace MetaModels\AttributeSelectBundle\ContaoManager;
22+
23+
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
24+
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
25+
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
26+
use Contao\ManagerPlugin\Routing\RoutingPluginInterface;
27+
use MetaModels\AttributeSelectBundle\MetaModelsAttributeSelectBundle;
28+
use MetaModels\CoreBundle\MetaModelsCoreBundle;
29+
use Symfony\Component\Config\Loader\LoaderResolverInterface;
30+
use Symfony\Component\HttpKernel\KernelInterface;
31+
32+
/**
33+
* Contao Manager plugin.
34+
*/
35+
class Plugin implements BundlePluginInterface, RoutingPluginInterface
36+
{
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
public function getBundles(ParserInterface $parser)
41+
{
42+
return [
43+
BundleConfig::create(MetaModelsAttributeSelectBundle::class)
44+
->setLoadAfter(
45+
[
46+
MetaModelsCoreBundle::class
47+
]
48+
)
49+
->setReplace(['metamodelsattribute_select'])
50+
];
51+
}
52+
53+
/**
54+
* {@inheritdoc}
55+
*/
56+
public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel)
57+
{
58+
$resolver
59+
->resolve(__DIR__ . '/../Resources/config/routing.yml')
60+
->load(__DIR__ . '/../Resources/config/routing.yml');
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* * This file is part of MetaModels/attribute_select.
5+
*
6+
* (c) 2012-2017 The MetaModels team.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* This project is provided in good faith and hope to be usable by anyone.
12+
*
13+
* @package MetaModels
14+
* @subpackage AttributeSelect
15+
* @author David Molineus <[email protected]>
16+
* @copyright 2012-2017 The MetaModels team.
17+
* @license https://github.com/MetaModels/attribute_text/blob/master/LICENSE LGPL-3.0
18+
* @filesource
19+
*/
20+
21+
namespace MetaModels\AttributeSelectBundle\DependencyInjection;
22+
23+
use Symfony\Component\Config\FileLocator;
24+
use Symfony\Component\DependencyInjection\ContainerBuilder;
25+
use Symfony\Component\DependencyInjection\Extension\Extension;
26+
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
27+
28+
/**
29+
* This is the Bundle extension.
30+
*/
31+
class MetaModelsAttributeSelectExtension extends Extension
32+
{
33+
/**
34+
* {@inheritDoc}
35+
*/
36+
public function load(array $configs, ContainerBuilder $container)
37+
{
38+
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
39+
$loader->load('services.yml');
40+
}
41+
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/**
4+
* * This file is part of MetaModels/attribute_select.
5+
*
6+
* (c) 2012-2017 The MetaModels team.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* This project is provided in good faith and hope to be usable by anyone.
12+
*
13+
* @package MetaModels
14+
* @subpackage AttributeSelect
15+
* @author Christian Schiffler <[email protected]>
16+
* @author David Greminger <[email protected]>
17+
* @author Ingolf Steinhardt <[email protected]>
18+
* @author David Molineus <[email protected]>
19+
* @copyright 2012-2017 The MetaModels team.
20+
* @license https://github.com/MetaModels/attribute_text/blob/master/LICENSE LGPL-3.0
21+
* @filesource
22+
*/
23+
24+
namespace MetaModels\AttributeSelectBundle;
25+
26+
use Symfony\Component\HttpKernel\Bundle\Bundle;
27+
28+
/**
29+
* The Bundle class.
30+
*/
31+
class MetaModelsAttributeSelectBundle extends Bundle
32+
{
33+
34+
}

src/Resources/config/services.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
metamodels.attribute_select.factory:
3+
class: MetaModels\AttributeSelectBundle\Attribute\AttributeTypeFactory
4+
arguments:
5+
- '@database_connection'
6+
- '@router'
7+
- '@session'
8+
- '@cca.dc-general.scope-matcher'
9+
tags:
10+
- { name: metamodels.attribute_factory }

src/deprecated-autoload.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/**
4+
* This file is part of MetaModels/attribute_select.
5+
*
6+
* (c) 2012-2017 The MetaModels team.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* This project is provided in good faith and hope to be usable by anyone.
12+
*
13+
* @package MetaModels
14+
* @subpackage AttributeSelect
15+
* @author David Molineus <[email protected]>
16+
* @copyright 2012-2017 The MetaModels team.
17+
* @license https://github.com/MetaModels/attribute_text/blob/master/LICENSE LGPL-3.0
18+
* @filesource
19+
*/
20+
21+
use MetaModels\AttributeSelectBundle\Attribute\AttributeTypeFactory;
22+
use MetaModels\AttributeSelectBundle\Attribute\Select;
23+
24+
// This hack is to load the "old locations" of the classes.
25+
spl_autoload_register(
26+
function ($class) {
27+
static $classes = [
28+
'MetaModels\Attribute\Select\Select' => Select::class,
29+
'MetaModels\Attribute\Select\AttributeTypeFactory' => AttributeTypeFactory::class
30+
];
31+
32+
if (isset($classes[$class])) {
33+
// @codingStandardsIgnoreStart Silencing errors is discouraged
34+
@trigger_error('Class "' . $class . '" has been renamed to "' . $classes[$class] . '"', E_USER_DEPRECATED);
35+
// @codingStandardsIgnoreEnd
36+
37+
if (!class_exists($classes[$class])) {
38+
spl_autoload_call($class);
39+
}
40+
41+
class_alias($classes[$class], $class);
42+
}
43+
}
44+
);

tests/Attribute/SelectAttributeTypeFactoryTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @filesource
2020
*/
2121

22-
namespace MetaModels\AttributeSelectBundle\Test;
22+
namespace MetaModels\AttributeSelectBundle\Test\Attribute;
2323

2424
use MetaModels\Attribute\IAttributeTypeFactory;
2525
use MetaModels\Attribute\Select\AttributeTypeFactory;

tests/Attribute/SelectTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @filesource
2020
*/
2121

22-
namespace MetaModels\AttributeSelectBundle\Test;
22+
namespace MetaModels\AttributeSelectBundle\Test\Attribute;
2323

2424
use MetaModels\Attribute\Select\MetaModelSelect;
2525
use MetaModels\Attribute\Select\Select;

tests/ContaoManager/PluginTest.php

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
/**
4+
* * This file is part of MetaModels/attribute_select.
5+
*
6+
* (c) 2012-2017 The MetaModels team.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* This project is provided in good faith and hope to be usable by anyone.
12+
*
13+
* @package MetaModels
14+
* @subpackage AttributeSelect
15+
* @author David Molineus <[email protected]>
16+
* @copyright 2012-2017 The MetaModels team.
17+
* @license https://github.com/MetaModels/attribute_text/blob/master/LICENSE LGPL-3.0
18+
* @filesource
19+
*/
20+
21+
namespace MetaModels\AttributeSelectBundle\Test\ContaoManager;
22+
23+
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
24+
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
25+
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
26+
use MetaModels\AttributeSelectBundle\ContaoManager\Plugin;
27+
use MetaModels\CoreBundle\MetaModelsCoreBundle;
28+
use PHPUnit\Framework\TestCase;
29+
use Symfony\Component\Config\Loader\LoaderInterface;
30+
use Symfony\Component\Config\Loader\LoaderResolverInterface;
31+
use Symfony\Component\HttpKernel\KernelInterface;
32+
33+
/**
34+
* Unit tests the contao manager plugin.
35+
*/
36+
class PluginTest extends TestCase
37+
{
38+
/**
39+
* Test that plugin can be instantiated.
40+
*
41+
* @return void
42+
*/
43+
public function testInstantiation()
44+
{
45+
$plugin = new Plugin();
46+
47+
$this->assertInstanceOf(Plugin::class, $plugin);
48+
$this->assertInstanceOf(BundlePluginInterface::class, $plugin);
49+
}
50+
51+
/**
52+
* Tests that the a valid bundle config is created.
53+
*
54+
* @return void
55+
*/
56+
public function testBundleConfig()
57+
{
58+
$parser = $this->getMockBuilder(ParserInterface::class)->getMock();
59+
$plugin = new Plugin();
60+
$bundles = $plugin->getBundles($parser);
61+
62+
$this->assertContainsOnlyInstancesOf(BundleConfig::class, $bundles);
63+
$this->assertCount(1, $bundles);
64+
65+
/** @var BundleConfig $bundleConfig */
66+
$bundleConfig = $bundles[0];
67+
68+
$this->assertEquals($bundleConfig->getLoadAfter(), [MetaModelsCoreBundle::class]);
69+
$this->assertEquals($bundleConfig->getReplace(), ['metamodelsattribute_select']);
70+
}
71+
72+
/**
73+
* Test if the routing config is loaded.
74+
*
75+
* @return void
76+
*/
77+
public function testRouting()
78+
{
79+
$loader = $this->getMockBuilder(LoaderInterface::class)->getMock();
80+
$resolver = $this->getMockBuilder(LoaderResolverInterface::class)->getMock();
81+
82+
$loader
83+
->expects($this->once())
84+
->method('load');
85+
86+
$resolver
87+
->expects($this->once())
88+
->method('resolve')
89+
->willReturn($loader);
90+
91+
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
92+
93+
$plugin = new Plugin();
94+
$plugin->getRouteCollection($resolver, $kernel);
95+
}
96+
}

0 commit comments

Comments
 (0)