vanio / vanio-testing-bundle
Symfony2 Bundle primarily helping you with integration testing.
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: 7.0.*
- html2text/html2text: ^4.0.1
- symfony/browser-kit: ^3.0
- symfony/framework-bundle: ^3.0
- vanio/stdlib: ^0.1@dev
Requires (Dev)
- doctrine/doctrine-fixtures-bundle: ^2.3
- doctrine/orm: ^2.5
- phpunit/phpunit: ^5.5
- sensio/framework-extra-bundle: ^3.0
- symfony/console: ^3.0
- symfony/css-selector: ^3.0
- vanio/coding-standards: ^0.1@dev
This package is auto-updated.
Last update: 2024-11-05 01:52:42 UTC
README
A Symfony2 Bundle primarily helping you with integration testing.
Installation
Installation can be done as usually using composer.
composer require vanio/vanio-testing-bundle
In case of testing bundle configuration you need to extend prepared Vanio\TestingBundle\HttpKernel\TestKernel
class.
It provides you access to TestContainerBuilder
you can use when testing bundle configurations.
This kernel is also pre-configured for easier creation of standalone bundle's testing environment.
<?php // AppKernel.php use Vanio\TestingBundle\HttpKernel\TestKernel; class AppKernel extends TestKernel {}
The default implementation of TestKernel
class expects you to create a file named
Tests/Functional/app/{environment}/bundles.php
relative to the kernel's root directory returning an array of
the bundles to register. You can specify the environment later inside your test case.
<?php // Tests/Functional/app/default/bundles.php return [ new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle, new Symfony\Bundle\FrameworkBundle\FrameworkBundle, new Vanio\TestingBundle\Tests\Functional\Bundle\TestBundle, ];
Similarly it expects you to create a configuration file named Tests/Functional/app/{environment}/config.yml
where
you can configure the bundles.
<?php // Tests/Functional/app/default/config.yml return [ new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle, new Symfony\Bundle\FrameworkBundle\FrameworkBundle, new Vanio\TestingBundle\Tests\Functional\Bundle\TestBundle, ];
Otherwise you can register this bundle classically inside your AppKernel
.
// app/AppKernel.php // ... class AppKernel extends Kernel { // ... public function registerBundles(): array { // ... if ($this->environment === 'test') { $bundles[] = new Vanio\TestingBundle\VanioTestingBundle; } // ... } }
The following examples are taken from actual tests of this bundle.
Testing Configuration of Bundle Extensions
// Tests/Functional/BundleConfigurationTest.php // ... use Vanio\TestingBundle\DependencyInjection\TestContainerBuilder; use Vanio\TestingBundle\PhpUnit\KernelTestCase; class ExtensionConfigurationTest extends KernelTestCase { function test_extension_configuration() { self::boot(); $this->assertInstanceOf(TestContainerBuilder::class, self::$container); $this->assertArraySubset( [ 'secret' => 'secret', 'form' => ['enabled' => false], 'profiler' => ['enabled' => false], 'router' => ['enabled' => true], ], self::$container->processExtensionConfig('framework') ); } }
Testing of Page Rendering
// Tests/Functional/PageRenderingTest.php // ... use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\HttpFoundation\Response; use Vanio\TestingBundle\PhpUnit\WebTestCase; class PageRenderingTest extends WebTestCase { function test_page_renders_successfully() { self::boot(); $response = $this->request('GET', '/test'); $this->assertInstanceOf(Response::class, $response); $this->assertSame(200, $response->getStatusCode()); $this->assertHtmlContainsText( ' HEADING Paragraph Link [/] ', $response->getContent() ); $this->assertHtmlNotContainsText('foo', $response->getContent()); } function test_crawling_page() { self::boot(); $this->request('GET', '/test'); $this->assertInstanceOf(Crawler::class, $this->crawler); $this->assertSame(1, $this->crawler->filter('html:contains("Heading")')->count()); } }