$ composer init #
composer.json file was created in the root directory. It has several sections of interest to us: require , require-dev , suggest . Let's go through each of them:require - without which our project cannot workrequire-dev is what we use for development and testingsuggest - here you can say that your bundle can work, for example, not only with ORM but also ODM$ composer install
bootstrap.php in the directory with our tests and indicate that phpunit should use it. <?php use Doctrine\Common\Annotations\AnnotationRegistry; //    Doctrine   use Composer\Autoload\ClassLoader; /** * @var ClassLoader $loader */ $loader = require __DIR__.'/../vendor/autoload.php'; AnnotationRegistry::registerLoader(array($loader, 'loadClass')); //    Doctrine   return $loader; Once again I want to draw your attention to the line AnnotationRegistry::registerLoader(array($loader, 'loadClass')); . My bundle uses Doctrine and annotations in full and for me it was a great surprise when I got an exception with the text "Annotation can not be loaded" over and over again.phpunit.xml.dist and indicate where our bootstrap.php <phpunit bootstrap="./Tests/bootstrap.php"> Tests/fixtures folder where the files related to our test application will be located. The key class of any symfony application is AppKernel , create it in the folder Tests/fixtures/app <?php use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; class AppKernel extends Kernel { /** * @return array */ public function registerBundles() { $bundles = array( //     ); return $bundles; } /** * @param \Symfony\Component\Config\Loader\LoaderInterface $loader */ public function registerContainerConfiguration(LoaderInterface $loader) { $loader->load(__DIR__ . '/config/config.yml'); } } Tests/fixtures/app/config/config.yml .Tests/fixtures/app/console file with the following content: #!/usr/bin/env php <?php // if you don't want to setup permissions the proper way, just uncomment the following PHP line // read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information //umask(0000); set_time_limit(0); require_once __DIR__.'/../../bootstrap.php'; require_once __DIR__.'/AppKernel.php'; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Debug\Debug; $input = new ArgvInput(); $env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev'); $debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod'; if ($debug) { Debug::enable(); } $kernel = new AppKernel($env, $debug); $application = new Application($kernel); $application->run($input); phpunit.xml.dist : <php> <server name="KERNEL_DIR" value="Tests/Fixtures/app/" /> </php> Symfony\Bundle\FrameworkBundle\Test\WebTestCase , with which we can test our services and stuff in the context of a Symfony 2 application.Source: https://habr.com/ru/post/221259/
All Articles