Hello,
I'm using seeInRepository() in my functional test (cest).
but I get the following error:
[Doctrine\Common\Annotations\AnnotationException] [Semantical Error] The annotation "@Doctrine\ORM\Mapping\Table" in class AppBundle\Entity\WebsitebutlerLog does not exist, or could not be auto-loaded.
-vvv mode for more details.Here you are the console output
1) DashboardControllerCest: New enquiry test
Test tests/functional/DashboardControllerCest.php:newEnquiryTest
[Doctrine\Common\Annotations\AnnotationException] [Semantical Error] The annotation "@Doctrine\ORM\Mapping\Table" in class AppBundle\Entity\WebsitebutlerLog does not exist, or could not be auto-loaded.
Scenario Steps:
4. $I->seeInRepository("AppBundle\Entity\WebsitebutlerLog","id",{"websitebutler":"3","message":"\n ...})
3. $I->grabTextFrom("h1")
2. $I->seeResponseCodeIs(200)
1. $I->amOnPage("/dashboard/enquiry")
/var/www/james/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php:708
/var/www/james/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php:641
/var/www/james/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php:334
/var/www/james/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php:195
/var/www/james/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/CachedReader.php:83
/var/www/james/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php:63
/var/www/james/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php:102
/var/www/james/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:151
/var/www/james/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:332
/var/www/james/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:78
/var/www/james/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:216
/var/www/james/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:281
/var/www/james/vendor/codeception/codeception/src/Codeception/Module/Doctrine2.php:360
/var/www/james/vendor/codeception/codeception/src/Codeception/Module/Doctrine2.php:340
/var/www/james/vendor/codeception/codeception/src/Codeception/Step.php:259
/var/www/james/vendor/codeception/codeception/src/Codeception/Scenario.php:69
/var/www/james/src/MyBundle/tests/_support/_generated/FunctionalTesterActions.php:2532
/var/www/james/src/MyBundle/tests/functional/DashboardControllerCest.php:40
/var/www/james/vendor/codeception/codeception/src/Codeception/Lib/Di.php:121
/var/www/james/vendor/codeception/codeception/src/Codeception/Test/Cest.php:131
/var/www/james/vendor/codeception/codeception/src/Codeception/Test/Cest.php:143
/var/www/james/vendor/codeception/codeception/src/Codeception/Test/Cest.php:77
/var/www/james/vendor/codeception/codeception/src/Codeception/Test/Test.php:82
/var/www/james/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
/var/www/james/vendor/codeception/codeception/src/Codeception/PHPUnit/Runner.php:98
/var/www/james/vendor/codeception/codeception/src/Codeception/SuiteManager.php:162
/var/www/james/vendor/codeception/codeception/src/Codeception/Codecept.php:209
/var/www/james/vendor/codeception/codeception/src/Codeception/Codecept.php:178
/var/www/james/vendor/codeception/codeception/src/Codeception/Command/Run.php:329
/var/www/james/vendor/codeception/codeception/src/Codeception/Command/Run.php:256
/var/www/james/vendor/symfony/console/Command/Command.php:256
/var/www/james/vendor/symfony/console/Application.php:818
/var/www/james/vendor/symfony/console/Application.php:186
/var/www/james/vendor/symfony/console/Application.php:117
/var/www/james/vendor/codeception/codeception/src/Codeception/Application.php:103
/var/www/james/vendor/codeception/codeception/codecept:33
FAILURES!
Tests: 2, Assertions: 2, Errors: 1.
THE ERROR HANDLER HAS CHANGED!
here you are my code
public function newEnquiryTest(FunctionalTester $I)
{
$I->amOnPage('/dashboard/enquiry');
$I->seeResponseCodeIs(200);
$message = $I->grabTextFrom('h1');
$I->seeInRepository(
WebsitebutlerLog::class,
'id',
array(
'CustomerId' => '3',
'message' => $message
)
);
}
"php": ">=5.5.9",
"symfony/symfony": "3.0.*",
"doctrine/orm": "^2.5",
composer show)behat/gherkin v4.4.4 Gherkin DSL parser for PHP 5.3
behat/transliterator v1.1.0 String transliterator
codeception/codeception 2.2.4 BDD-style testing framework
devio/pipedrive 1.0.0 Complete Pipedrive API client for PHP
doctrine/annotations v1.2.7 Docblock Annotations Parser
doctrine/cache v1.6.0 Caching library offering an object-oriented API for man...
doctrine/collections v1.3.0 Collections Abstraction library
doctrine/common v2.6.1 Common Library for Doctrine projects
doctrine/data-fixtures v1.1.1 Data Fixtures for all Doctrine Object Managers
doctrine/dbal v2.5.5 Database Abstraction Layer
doctrine/doctrine-bundle 1.6.4 Symfony DoctrineBundle
doctrine/doctrine-cache-bundle 1.3.0 Symfony Bundle for Doctrine Cache
doctrine/doctrine-fixtures-bundle 2.3.0 Symfony DoctrineFixturesBundle
doctrine/inflector v1.1.0 Common String Manipulations with regard to casing and s...
doctrine/instantiator 1.0.5 A small, lightweight utility to instantiate objects in ...
doctrine/lexer v1.0.1 Base library for a lexer that can be used in Top-Down, ...
doctrine/orm v2.5.5 Object-Relational-Mapper for PHP
egeloen/lucene-search-bundle 2.0.1 Provides a zend lucene search integration for your Symf...
facebook/webdriver 1.1.3 A PHP client for WebDriver
guzzlehttp/guzzle 6.2.1 Guzzle is a PHP HTTP client library
guzzlehttp/promises 1.2.0 Guzzle promises library
guzzlehttp/psr7 1.3.1 PSR-7 message implementation
illuminate/contracts v5.2.45 The Illuminate Contracts package.
illuminate/support v5.2.45 The Illuminate Support package.
imagin/fotolia-api dev-master 485c279 Composer package of the Fotolia API toolkit
intervention/image 2.3.8 Image handling and manipulation library with support fo...
jdorn/sql-formatter v1.2.17 a PHP SQL highlighting library
knplabs/doctrine-behaviors 1.3.2 Doctrine2 behavior traits
knplabs/knp-menu v2.1.1 An object oriented menu library
knplabs/knp-menu-bundle 2.1.2 This bundle provides an integration of the KnpMenu library
leafo/lessphp v0.4.0 lessphp is a compiler for LESS written in PHP.
leafo/scssphp v0.0.12 scssphp is a compiler for SCSS written in PHP.
leaseweb/memcache-bundle v2.1.10 Memcache Doctrine caching and session storage in the We...
mashape/unirest-php v3.0.4 Unirest PHP
monolog/monolog 1.21.0 Sends your logs to files, sockets, inboxes, databases a...
oro/doctrine-extensions 1.0.12 Doctrine Extensions for MySQL and PostgreSQL.
paragonie/random_compat v1.4.1 PHP 5.x polyfill for random_bytes() and random_int() fr...
phpdocumentor/reflection-common 1.0 Common reflection classes used by phpdocumentor to refl...
phpdocumentor/reflection-docblock 3.1.0 With this component, a library can provide support for ...
phpdocumentor/type-resolver 0.2
phpspec/prophecy v1.6.1 Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage 2.2.4 Library that provides collection, processing, and rende...
phpunit/php-file-iterator 1.4.1 FilterIterator implementation that filters files based ...
phpunit/php-text-template 1.2.1 Simple template engine.
phpunit/php-timer 1.0.8 Utility class for timing
phpunit/php-token-stream 1.4.8 Wrapper around PHP's tokenizer extension.
phpunit/phpunit 4.8.27 The PHP Unit Testing framework.
phpunit/phpunit-mock-objects 2.3.8 Mock Object library for PHPUnit
psr/http-message 1.0.1 Common interface for HTTP messages
psr/log 1.0.1 Common interface for logging libraries
sebastian/comparator 1.2.0 Provides the functionality to compare PHP values for eq...
sebastian/diff 1.4.1 Diff implementation
sebastian/environment 1.3.8 Provides functionality to handle HHVM/PHP environments
sebastian/exporter 1.2.2 Provides the functionality to export PHP variables for ...
sebastian/global-state 1.1.1 Snapshotting of global state
sebastian/recursion-context 1.0.2 Provides functionality to recursively process PHP varia...
sebastian/version 1.0.6 Library that helps with managing the version number of ...
sensio/distribution-bundle v5.0.12 Base bundle for Symfony Distributions
sensio/framework-extra-bundle v3.0.16 This bundle provides a way to configure your controller...
sensio/generator-bundle v3.0.8 This bundle generates code for you
sensiolabs/security-checker v3.0.2 A security checker for your composer.lock
shark/simple_html_dom dev-master 842b3fc Simple HTML DOM package.
swiftmailer/swiftmailer v5.4.3 Swiftmailer, free feature-rich PHP mailer
symfony/console v3.1.4 Symfony Console Component
symfony/monolog-bundle 2.11.1 Symfony MonologBundle
symfony/phpunit-bridge v3.1.4 Symfony PHPUnit Bridge
symfony/polyfill-intl-icu v1.2.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring v1.2.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php56 v1.2.0 Symfony polyfill backporting some PHP 5.6+ features to ...
symfony/polyfill-php70 v1.2.0 Symfony polyfill backporting some PHP 7.0+ features to ...
symfony/polyfill-util v1.2.0 Symfony utilities for portability of PHP codes
symfony/swiftmailer-bundle v2.3.11 Symfony SwiftmailerBundle
symfony/symfony v3.0.9 The Symfony PHP framework
twig/extensions v1.3.0 Common additional features for Twig that do not directl...
twig/twig v1.24.2 Twig, the flexible, fast, and secure template language ...
webmozart/assert 1.1.0 Assertions to validate method input/output with nice er...
zendframework/zend-hydrator 1.1.0
zendframework/zend-stdlib 2.7.7
zendframework/zendsearch dev-master c8de250 a general purpose text search engine written entirely i...
class_name: FunctionalTester
modules:
enabled:
- Symfony:
var_path: '../../var'
app_path: '../../app'
- Doctrine2:
depends: Symfony
- PhpBrowser:
url: 'http://localhost/app_dev.php/'
auth: ['user', 'pass']
- \MyBundle\Helper\Functional
It is worth mentioning that when I explicitly include the autoloader in the test _bootstrap.php file as follow:
// I can assure you the path is correct
require_once '../../../vendor/autoload.php';
I get the following error:
$ vendor/bin/codecept run -c src/MyBundle -vvv
PHP Warning: require_once(../../../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/james/src/MyBundle/tests/_bootstrap.php on line 3
PHP Fatal error: require_once(): Failed opening required '../../../vendor/autoload.php' (include_path='.:/usr/share/php') in /var/www/james/src/MyBundle/tests/_bootstrap.php on line 3
adding the autoload to the _bootstrap.php in the functional suite folder gives me the same error.
Thank you for your help.
p.s. All of my @ORM annotations are fine and working with no problem everywhere in my app.
require_once __DIR__ . '/../../../vendor/autoload.php';
Don't enable PhpBrowser and Symfony modules in the same suite.
Thank you Naktibalda.
Imagine a situation where I have to fetch some data from repository (Symfony/Doctrine) and compare them with the result coming from a page response (PhpBrowser).
It seems to me that I need them both. Can you give me some insight on this please?
Your configuration should not even run with Codeception 2.2.
You don't need to enable Symfony module,
it is enough to enable Doctrine2 and configure it to use Symfony.
- Doctrine2:
depends: Symfony
Set configuration options for Symfony module in modules config section:
modules:
config:
- Symfony:
var_path: '../../var'
app_path: '../../app'
Also you have to set cleanup: false option for Doctrine2 module.
If cleanup is enabled, Doctrine2 module wraps entire test in transaction and the test can't see changes made by other connections.
Thanks again Naktibalda. I did as you instructed but I got 'bootstrap file not found' error.
(Also finally It complained about the conflict between PhpBrowser and Symfony.)
I'm looking at the documentation here
modules:
enabled:
- Symfony
- Doctrine2:
depends: Symfony
and it seems it is ok to enable both side by side.
Unfortunately the github demo didn't provide that much help either.
I wonder if you are kind enough to post config settings for codeception.yml and functional.suite.yml here (given that I need to compare the Database entities with the contents of Page responses).
Thank you very much.
Yes it is ok to enable Symfony and Doctrine2 if PhpBrowser is not enabled.
Ok, So I have this weird setup which according to the documentation shouldn't work:
# functional.suite.yml
class_name: FunctionalTester
modules:
enabled:
- Symfony:
var_path: '../../var'
app_path: '../../app'
- Doctrine2:
depends: Symfony
cleanup: false
- PhpBrowser:
url: 'http://my.websitebutler.local/app_dev.php/'
But it works fine (if I remove PhpBrowser, I can't reference any HTML element and none of those grabTextFrom(), fillField(), click(), etc methods will work. So I need PhpBrowser or WebDriver to make sure I can run my tests.) So lets move on for now and if I found the answer I will share it here.
Back to my original question, I still can't find any solution for Doctrine annotation issue.
When I use $I->seeInRepository() I get annotation exception.
Any idea why is that happening?
i fix that in implementing this:
In the file _tests/_bootstrap.php_
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
I'm using codecept with symfony 2.8 + doctrine 2 + ApiTests
In file _codeception.yml_ i have:
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
# envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
Symfony:
app_path: 'app'
var_path: 'var'
enviroment: 'dev'
Doctrine2:
cleanup: true
depends: Symfony
And in file _tests/api.suite,yml_
class_name: ApiTester
modules:
enabled:
- Symfony
- REST:
url: /
depends: Symfony
part: Json
- Doctrine2
- \Helper\Api
@pablis00 Thank you very much for posting your solution!
I ran into the same problem wit Codeception 2.2.6 in Symfony 3.1 and adding the AnnotationRegistry to the bootstrap file works like a charm 馃憤
Most helpful comment
i fix that in implementing this:
In the file _tests/_bootstrap.php_
I'm using codecept with symfony 2.8 + doctrine 2 + ApiTests
In file _codeception.yml_ i have:
And in file _tests/api.suite,yml_