Code Monkey home page Code Monkey logo

testing's Introduction

Symfony CMF Testing

Tests Latest Stable Version License

Total Downloads Monthly Downloads

This package is part of the Symfony Content Management Framework (CMF) and licensed under the MIT License.

NOTE: This is an internal tool and is not intended to be used outside of the context of the CMF.

Documentation

For the install guide and reference, see:

Support

For general support and questions, please use StackOverflow.

Contributing

Pull requests are welcome. Please see our CONTRIBUTING guide.

Thanks to everyone who has contributed already.

License

This package is available under the MIT license.

testing's People

Contributors

acrobat avatar alexander-schranz avatar apiciuspoulet avatar cordoval avatar covex-nn avatar damienflament avatar dantleech avatar dbu avatar electricmaxxx avatar emmanuelvella avatar franmomu avatar greg0ire avatar jordisala1991 avatar krichprollsch avatar lsmith77 avatar stylecibot avatar trsteel88 avatar wouterj avatar xabbuh avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

testing's Issues

Framework versions don't work

In travis, we used a SYMFONY_VERSION variable to determine the Symfony version. If a bundle intergrated this Testing component, this does no longer work.

To problem is that this bundle always installs the latest symfony version. That does include the latest FrameworkBundle, so the older version set by the bundle isn't used.

To fix this, we need to change all .travis.yml files from:

before_script:
    # ...
    - composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source
    # ...

To:

before_script:
    # ...
    - composer require symfony/symfony:${SYMFONY_VERSION} --prefer-source
    # ...

And change this composer.json file to accept any version of Symfony2

The container used by the client is different from the container used by the db manager in Function BaseTestCase

@dbu @dantleech @briancappello

We discussed in symfony-cmf/menu-bundle#215 that there are 2 different containers which are created when you have a functional test that extends the BaseTestCase

  1. The client creates a container which is used when processing requests
  2. Any calls to $this->getContainer or $this->db($type) use a different container

This can cause issues with the 2 containers getting out of sync, for example if you delete a PHPCR node in a functional test and then try to find it in the DB to ensure its not there you can inadvertently end up using 2 different containers and trigger a PHPCR\InvalidItemStateException

this->db() proxies to this->getContainer, which creates a client and gets the container from it and throws it away.

https://github.com/symfony-cmf/Testing/blob/master/src/Functional/BaseTestCase.php#L58

Instead we could store an internal reference to the client as follows

    public function getContainer()
    {
        if (!$this->client) {
            $this->client = $this->createClient($this->getKernelConfiguration());
        }
        $this->container = $this->client->getContainer();

        return $this->container;
    }

why explicit dependency on 1.0.x-dev?

this leads to the following composer problem when trying to install this in the sandbox:

- symfony-cmf/testing 1.0.x-dev requires doctrine/phpcr-bundle 1.0.x-dev -> satisfiable by doctrine/phpcr-bundle[1.0.x-dev].
- Installation request for symfony-cmf/testing 1.0.* -> satisfiable by symfony-cmf/testing[1.0.x-dev].

Symfony 4.1 support

PHP Fatal error: Cannot redeclare static Symfony\Bundle\FrameworkBundle\Test\WebTestCase::$container as non static Symfony\Cmf\Component\Testing\Functional\BaseTestCase::$container in .../phpcr-migrations-bundle/vendor/symfony-cmf/testing/src/Functional/BaseTestCase.php on line 27

https://github.com/symfony-cmf/testing/blob/dd8d71d62e7b5cf4f3e46af4ba0fe3ee2dd2decc/src/Functional/BaseTestCase.php#L39

https://github.com/symfony/framework-bundle/blob/39156eb4298d4cc28f6d5d23af10fb2f246e5529/Test/KernelTestCase.php#L36

https://travis-ci.org/dantleech/phpcr-migrations-bundle/jobs/387870194#L556

Find a way to use both doctrine bundle sets in one application

I tried to load bundleSets phpcr_odm and doctrine_orm in one application cause i got a test where i need both. But unfortunately i got an Exception:

 LogicException : Trying to register two bundles with the same name "DoctrineBundle"

what completely ok as the bundleSets looks like:

        $this->registerBundleSet('phpcr_odm', array(
            'Doctrine\Bundle\DoctrineBundle\DoctrineBundle',
            'Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle',
        ));

        $this->registerBundleSet('doctrine_orm', array(
            'Doctrine\Bundle\DoctrineBundle\DoctrineBundle',
        ));

what i would suggest is to "upgrade" the Doctrine\Bundle\DoctrineBundle\DoctrineBundle to the default setting as it is in the Symfony SE too. But what would be the Bundle to load in the doctrine_orm section?
I am lookin for bundle like doctrine-orm-bundle, but i think the structure (Bundle <-> Library) isn'tt really consistent, or?

Deprecate included config files

Currently, Testing includes lots of config files. I think it's best to remove all included configuration apart from framework.secret (which is the minimal config requried to get the AppKernel running with FrameworkBundle).

A bundle then needs to include its own config, allowing them to configure it exactly to fit their needs. This also avoids things like #113.

/cc @dantleech @lsmith77 @dbu Let's make a decision about this soon, so we can trigger deprecation notices in 1.3 (which will be released very soon).

Initializer forgotten for fixture loader?

Since PHPCR-ODM 1.2 the initializers of the the bundles will be load before the fixture loader starts to work. I have no clue how that works, but it seems that the initializer does not start to work for test fixtures. I know that test can be on different paths, but sometimes i wanna work on the original node system.

Possible to add the initlializer?

It would be possible to register test nodes by a specif TestInitializerconfiguration. But atm i just got an empty tree.

Test with processIsolation="true"

Hello,

Great feature, thanks a lot for this bundle.

To run test with processIsolation="true" on phpunit.xml there is an error: PHPUnit_Framework_Exception : Notice: Constant CMF_TEST_ROOT_DIR already defined in vendor\symfony-cmf\testing\bootstrap\bootstrap.php on line 32

To resolve this issue I change lines 32 and 33 to this file with this code:

if (!defined('CMF_TEST_ROOT_DIR')) {
    define('CMF_TEST_ROOT_DIR', realpath(__DIR__.'/..'));
}
if (!defined('CMF_TEST_CONFIG_DIR')) {
    define('CMF_TEST_CONFIG_DIR', CMF_TEST_ROOT_DIR.'/resources/config');
}

I don't create a pull request because I'm not familiar with them.

Have a nice day.

Regards,

[RFC] Loader for both manager

I know that this one does not exist in reality, but i would like to have a fixture loader where i have got access to both managers (PHPCR, ORM).

We should keep the common interface of the loader (build(ObjectManager $manager)) and just add a setter for the second one. As our testing component creates them we should be able to inject the second manager.

Yea ... My DoctrineAdapter still supports a solution to create the referenced document by default just by setting:

$entity->setDocument($document);
$manager->persist($entity);

(other way around works too)
what means that i won't need the second manager, but there are use cases when i need it:

  • path creation by the help of the NodeHelper

But that leads my to a second solution: What about creating a parameter injection from the test, that would solve my problems too.

An advantage would be to purge both storages in one strike.

crash about getClient since sf 4.3.0

Environment1

Symfony packages

symfony/asset                      v4.3.2  v4.3.2  Symfony Asset Component
symfony/browser-kit                v4.3.2  v4.3.2  Symfony BrowserKit Component
symfony/cache                      v4.3.2  v4.3.2  Symfony Cache component with PSR-6, PSR-16, and tags
symfony/cache-contracts            v1.1.5  v1.1.5  Generic abstractions related to caching
symfony/config                     v4.3.2  v4.3.2  Symfony Config Component
symfony/console                    v4.3.2  v4.3.2  Symfony Console Component
symfony/css-selector               v4.3.2  v4.3.2  Symfony CssSelector Component
symfony/debug                      v4.3.2  v4.3.2  Symfony Debug Component
symfony/dependency-injection       v4.3.2  v4.3.2  Symfony DependencyInjection Component
symfony/doctrine-bridge            v4.3.2  v4.3.2  Symfony Doctrine Bridge
symfony/dom-crawler                v4.3.2  v4.3.2  Symfony DomCrawler Component
symfony/event-dispatcher           v4.3.2  v4.3.2  Symfony EventDispatcher Component
symfony/event-dispatcher-contracts v1.1.5  v1.1.5  Generic abstractions related to dispatching event
symfony/expression-language        v4.3.2  v4.3.2  Symfony ExpressionLanguage Component
symfony/filesystem                 v4.3.2  v4.3.2  Symfony Filesystem Component
symfony/finder                     v4.3.2  v4.3.2  Symfony Finder Component
symfony/form                       v4.3.2  v4.3.2  Symfony Form Component
symfony/framework-bundle           v4.3.2  v4.3.2  Symfony FrameworkBundle
symfony/http-foundation            v4.3.2  v4.3.2  Symfony HttpFoundation Component
symfony/http-kernel                v4.3.2  v4.3.2  Symfony HttpKernel Component
symfony/inflector                  v4.3.2  v4.3.2  Symfony Inflector Component
symfony/intl                       v4.3.2  v4.3.2  A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/mime                       v4.3.2  v4.3.2  A library to manipulate MIME messages
symfony/monolog-bridge             v4.3.2  v4.3.2  Symfony Monolog Bridge
symfony/monolog-bundle             v3.4.0  v3.4.0  Symfony MonologBundle
symfony/options-resolver           v4.3.2  v4.3.2  Symfony OptionsResolver Component
symfony/phpunit-bridge             v4.3.2  v4.3.2  Symfony PHPUnit Bridge
symfony/polyfill-ctype             v1.11.0 v1.11.0 Symfony polyfill for ctype functions
symfony/polyfill-intl-icu          v1.11.0 v1.11.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn          v1.11.0 v1.11.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-mbstring          v1.11.0 v1.11.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72             v1.11.0 v1.11.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73             v1.11.0 v1.11.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/process                    v4.3.2  v4.3.2  Symfony Process Component
symfony/property-access            v4.3.2  v4.3.2  Symfony PropertyAccess Component
symfony/routing                    v4.3.2  v4.3.2  Symfony Routing Component
symfony/security-acl               v3.0.2  v3.0.2  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle            v4.3.2  v4.3.2  Symfony SecurityBundle
symfony/security-core              v4.3.2  v4.3.2  Symfony Security Component - Core Library
symfony/security-csrf              v4.3.2  v4.3.2  Symfony Security Component - CSRF Library
symfony/security-guard             v4.3.2  v4.3.2  Symfony Security Component - Guard
symfony/security-http              v4.3.2  v4.3.2  Symfony Security Component - HTTP Integration
symfony/serializer                 v4.3.2  v4.3.2  Symfony Serializer Component
symfony/service-contracts          v1.1.5  v1.1.5  Generic abstractions related to writing services
symfony/templating                 v4.3.2  v4.3.2  Symfony Templating Component
symfony/translation                v4.3.2  v4.3.2  Symfony Translation Component
symfony/translation-contracts      v1.1.5  v1.1.5  Generic abstractions related to translation
symfony/twig-bridge                v4.3.2  v4.3.2  Symfony Twig Bridge
symfony/twig-bundle                v4.3.2  v4.3.2  Symfony TwigBundle
symfony/validator                  v4.3.2  v4.3.2  Symfony Validator Component
symfony/var-exporter               v4.3.2  v4.3.2  A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/yaml                       v4.3.2  v4.3.2  Symfony Yaml Component

Symfony CMF packages

symfony-cmf/resource             1.1.0  1.1.0  Bundle which facilitates document resource location via Puli
symfony-cmf/resource-bundle      1.1.0  1.1.0  Bundle which facilitates document resource location
symfony-cmf/resource-rest-bundle 1.1.0  1.1.0  Bundle which provides a REST API for resources
symfony-cmf/testing              2.1.11 2.1.11 Component providing tools for writing tests with Symfony.
symfony-cmf/tree-browser-bundle  2.1.1  2.1.1  Symfony CMF Tree Browser Bundle

Subject

Since symfony/symfony@4f91020 , that ships with 4.3.0, there is a collision between private static function getClient(KernelBrowser $newClient = null): ?KernelBrowser https://github.com/symfony/symfony/blob/950306adaad8b23725c4efeaf6c570d89e17f164/src/Symfony/Bundle/FrameworkBundle/Test/WebTestAssertionsTrait.php#L189 and

public function getClient()

Steps to reproduce

Retry this job: run what this job runs: https://travis-ci.org/sonata-project/SonataDoctrinePhpcrAdminBundle/jobs/556144893#L656

Expected results

No crash

Actual results

A crash

Speed up testing

With the CMF tests, we have a very big problem with the execution time of the tests on travis. They take way to long to fix problems with the tests on travis and to have quick merges. This issue will be a list of things we can do in order to speed up the tests.
I'll start with my ideas.

Cleanup Composer Dependencies

The slowest part is Composer, we may be able to speed that up a bit if we cleanup the dependencies. Not everything is really needed for each bundle and in a bundle, there may be some unused packages installed too.

Do not run every Sf2 version for every PHP version

We are currently testing 3 PHP versions for each supported Sf release. That means it we have currently 9 jobs. All jobs take up to 45 minutes and they aren't really run at the same time. We can quicken the test up by only running one Sf2 release to all PHP versions and the rest only against one PHP version.

Drop Symfony 2.2 support

We have 3 jobs running for Symfony 2.2. Symfony 2.2 has reached end of maintenance months ago, we should stop supporting and testing it imo.

@symfony-cmf/owners

Registering route annotations for controllers in bundle-under-test doesn't seem to work

The error: Cannot load resource "@VdwCmsBundle/Controller/PageController.php". Make sure the "VdwCmsBundle" bundle is correctly registered and loaded in the application kernel class.

Tests/Resources/app/AppKernel.php

<?php

use Symfony\Cmf\Component\Testing\HttpKernel\TestKernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends TestKernel
{
    public function configure()
    {
        $this->requireBundleSets(array(
            'default',
            'phpcr_odm',
            'sonata_admin_phpcr',
        ));

        $this->addBundles(array(
            // ....
            new \Vdw\CmsBundle\VdwCmsBundle(), // bundle under test
        ));
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load(__DIR__.'/config/config.php');
    }
}

Tests/Resources/app/config/routing.yml (loaded by config.php)

# ...
page_controller:
    resource: '@VdwCmsBundle/Controller/PageController.php'
    type: annotation

I also tried using an absolute path to the controller, and a relative path from the bundle root (eg Controller/PageController.php). Any ideas of what might be causing this to not work? Thanks!

database drop for doctrine_orm.sh

Is there a chance to put a (optional if exist) doctrine:database:drop --force at the beginning of the bin/travis/doctrine_orm.sh?
Most of the times working/testing with ORM and PHPCR i am playing with the mappings. Ether i call doctrine:schema:update every time or wanna just run a bash-script if i changed some stuff.

strange behavior for using orm/phpcr in one test

As i am working on a project where i need to touch different doctrines. I need to work with ORM and PHPCR in on test. Problem is the environment binding.
Setting environment to orm causes some issues with the PHPCR (test node creation, initializer, ..), but doesn't set it causes errors with not loaded orm configuration. Ok i can do the last on my own, but it would be nice to have a default environment with both or a new one for both or the best: bind the configuration on the registered bundles?

have test for xml bundle configuration

it would be great to have a base test to help with first loading a bundle xml configuration file, then validate it both with the xml schema and the Configuration class to be sure they both expect the same.

HHVM issue

Fatal error: Declaration of Symfony\Cmf\Component\Testing\Phpunit\DatabaseTestListener::addRiskyTest() must be compatible with that of PHPUnit_Framework_TestListener::addRiskyTest() in /home/travis/build/symfony-cmf/CoreBundle/vendor/symfony-cmf/testing/src/Phpunit/DatabaseTestListener.php on line 22

[2.0] make the Testing component useful for non CMF Bundles

it might be interesting to make this component useful for non CMF users as there is a lot of useful things in there to make functional testing for Bundles easier to setup.

also it might get some people to have a closer look at the CMF too :)

Overwrite templates in Resources folder seems not to work

Tried to debug the error in symfony-cmf/seo-bundle#177 There want to implement a test where i needet to overwrite the TwigBundle:Exception:exception_full.html.twig in a test. So i created a copy in Tests/Resources/app/Resources/TwigBundle/views/Exception/exception.html.twig which seems to be the right folder. But not for the Symfony cache of the test application. While debugging, i saw that the application tries to render the orignal template in the TwigBundle.

Any ideas for the place to put the templates? Or does the test application does not add my template?

Support use of a second workspace/PHPCR manager

A number of bundles now support using more than one PHPCR document manager, so there needs to be a way to easily add functional tests for this behaviour.

One use case seen so far with different document managers is using multiple workspaces, so it would probably be useful to include these too if possible.

Perhaps I can try to do this, but wanted to get a sanity check first.

Remove feature packages from composer require section

This package should not require things that should either not be required or be hard dependencies of the package being tested. As is, we might hide missing requirements.

But we will need to test all cmf bundles to know if we are doing it right, so its quite an effort.

Follow-up of #163

  • framework-bundle needs to be included with minimum 2.8.1 because if not is missing a dependency that is used by the bundle itself (kind of a bug). The dependency missing was: finder, and it was used only internally by the framework-bundle. I think this bug is only present if you want to use something related to the console, so might not be an issue for other bundles (not requiring minimum of 2.8.1) but it is in this case.
  • browser-kit needs to be added even though there is no use Symfony\ because it is a require-dev dependency on framework-bundle and they say: if you want to use webtestcase just require it.

symfony/phpunit-bridge is not in the requirements because: If someone wants to use simple-phpunit it is better that they require it directly. Imagine if you dont do it: if someday simfony decides to rename in a major the executable and you are not requiring it, you will end with broken builds. This happened once with twig on sonata, because twig upgraded to 2.0 breaking many things but no one had this dependency declared

build is failing

the build of the testing itself is failing. not sure if its a problem for bundles using it or just an invalid test...

Container / Kernel Instantiation.

Kernel instantiation is done with the help of the WebTestCase class, I find this to be more of a hinderance than a benefit.

  1. It "magically" finds the kernel class.
  2. It only allows for one instance of the kernel at one time.
  3. It makes the task seem much harder than it is.
public function getContainer()
{
    $kernel = new AppKernel();
    $kernel->boot();
    return $kernel->getContainer();
}

The user can then include their actual test kernel themselves (I don't think it is too much to ask).

I would vote to stop extending the WebTestCase and support a way to get a container instance with a specific configuration, for example:

public function getContainer($config = array(), $env, $debug)

wdyt?

Remove coupling to the kernel environment, use ENV variables

Currently we decide which configuration to use based on the kernel environment, i.e. either phpcr or orm.

In hindsight I do not think this was a good idea.

  • It implies that we only ever have variations for the PHPCR persistence layer.
  • It breaks applciations that depend on the value of the kernel enviornment for other reasons.

For example in SuluCMF we are doing the following:

// ../TestBundle/Resources/config.php
<?php

$kernelRootDir = $container->getParameter('kernel.root_dir');
$bundleName = null;

$phpcr = getenv('SULU_PHPCR');
$phpcr = $phpcr ? : 'jackrabbit';
$orm = getenv('SULU_ORM');
$orm = $orm ? : 'mysql';

$loader->import('sulu.yml');
$loader->import('phpcr_' . $phpcr . '.yml');
$loader->import('orm_' . $orm . '.yml');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.