# \[Solved\] Plugin Tests Problem

**URL:** <https://forum.shopware.com/t/solved-plugin-tests-problem/45424>\
**Category:** Programmierung\
**Created:** [25. April 2017 um 13:45 UTC](https://forum.shopware.com/t/solved-plugin-tests-problem/45424 "2017-04-25T13:45:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Bottner](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@Daniel\_Bottner](https://forum.shopware.com/u/Daniel_Bottner)\
**Post date:** [25. April 2017 um 13:45 UTC](https://forum.shopware.com/t/solved-plugin-tests-problem/45424/1 "2017-04-25T13:45:07Z")

</div>

Ich wollte mich endlich mal mit Unittest beschäftigen um die Entwicklungszykeln für unsere Plugins in Zukunft zu verkürzen.

Leider scheitere ich schon daran die Klassen für die ich Tests schreiben möchte in meine Testklassen zu laden.  
In der Hoffnung das mir geholfen werden kann hier grob die Struktur des Plugins sowie der Tests:

Das ganze ist Shopware \_ **5.2.21** \_

In **_engine/Shopware/Plugins/Community/Frontend/MyPlugin&nbsp;_** wird das Plugin auf den entsprechenden NS (‘MyPlugin’) registriert.

In der **phpunit.xml.dist&nbsp;** ist entsprechendes folgendes zu finden:

```
            ./Tests/Functional
            ./Tests/Unit
        

        
            ./Tests/Unit
        

        
            ./Tests/Functional
        
    

    
        
            disable
        
    

    
        
            ./

```

In \_ **MyPlugin/Tests/bootstrap.php** \_

```
boot();

        $container = $kernel->getContainer();
        $container->get('plugins')->Core()->ErrorHandler()->registerErrorHandler(E_ALL | E_STRICT);

        /** @var $repository \Shopware\Models\Shop\Repository */
        $repository = $container->get('models')->getRepository('Shopware\Models\Shop\Shop');

        $shop = $repository->getActiveDefault();
        $shop->registerResources();

        if (!self::assertPlugin('MyPlugin')) {
            throw new \Exception("Plugin MyPlugin must be installed.");
        }

        Shopware()->Loader()->registerNamespace('MyPlugin\Tests', __DIR__. '/../Tests/');
        Shopware()->Loader()->registerNamespace('Tests\Helper', __DIR__. '/Helper/');
        Shopware()->Loader()->registerNamespace('Shopware\Components', __DIR__. '/../Components/');
        Shopware()->Loader()->registerNamespace('Shopware\CustomModels', __DIR__. '/../Models/');

        self::registerResources();
    }
    /**
     * @param string $name
     * @return boolean
     */
    private static function assertPlugin($name)
    {
        $sql = 'SELECT 1 FROM s_core_plugins WHERE name = ? AND active = 1';

        return (boolean) Shopware()->Container()->get('dbal_connection')->fetchColumn($sql, [$name]);
    }

    /**
     * Registers all necessary classes to the di container.
     */
    private static function registerResources()
    {
    }
}

NyPluginTestKernel::start();
~

```

In \_ **MyPlugin/Tests/Functional/MyPluginTest.php** \_

Der entsprechende Helper liegt unter \_ **MyPlugin/Components/** \_ und sieht grob wie folgt aus:

Jede Hilfe ist willkommen.

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [25. April 2017 um 15:05 UTC](https://forum.shopware.com/t/solved-plugin-tests-problem/45424/2 "2017-04-25T15:05:30Z")

</div>

Hallo Daniel,

versuche mal im Testkernel auch den normalen Plugin-Namespace zu registrieren:

```
Shopware()->Loader()->registerNamespace('MyPlugin', __DIR__. '/../');

```

Viele Grüße aus Schöppingen

![cool](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/86c57fbace799dd4eb1f1b8a2d3bdc1733f0aea1.png "cool")&nbsp;Michael Telgmann
