Chapters
23 Chapters
|
1:59:49
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: >=5.4.0, <7.3.0
Subscribe to download the code!Compatible PHP versions: >=5.4.0, <7.3.0
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
13.
Controlling the Database
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial uses a very old version of Symfony. The fundamentals of Behat are still valid, but integration with Symfony will be different.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=5.4.0, <7.3.0",
"symfony/symfony": "^2.7", // v2.7.4
"twig/twig": "^1.22", // v1.22.1
"sensio/framework-extra-bundle": "^3.0", // v3.0.16
"doctrine/doctrine-bundle": "^1.5", // v1.5.1
"doctrine/orm": "^2.5", // v2.5.1
"doctrine/doctrine-fixtures-bundle": "^2.2", // v2.2.1
"behat/symfony2-extension": "^2.0" // v2.0.0
},
"require-dev": {
"behat/mink-extension": "^2.0", // v2.0.1
"behat/mink-goutte-driver": "^1.1", // v1.1.0
"behat/mink-selenium2-driver": "^1.2", // v1.2.0
"phpunit/phpunit": "^4.8" // 4.8.18
}
}
16 Comments
I have no /app/ directory in my framework, how should I download it?
require_once __DIR__.'/../../app/autoload.php'; => this line is not compiling because of missing /app/
Hey Soltan
That "app" folder doesn't exist anymore since Symfony4, so don't worry if you dont have it. Instead of requiring
app/autoload.phpyou should require composer's autoload ->rootApp/vendor/autoload.phpCheers!
I installed Behat\Symfony2Extension: as in tutorial but when I run feature file I have this error:
Class AppKernel does not exist
How can I fix it?
Ohh, yes, you have to specify from where to load the Kernel. You need to add something like this into your behat.yml file
Think thats a bit too many steps to follow. use this extension to make your lives easier http://inevitabletech.uk/bl...
Hey Ryan,
I've just started a Symfony 4 app (actually skeleton on 3.4). Is this still the "right way" to handle persisting users before testing them?
Cheers,
Tom
Hey tomhv
There is an easier way to setup your Symfony's container by installing & configuring the symfony-behat extension https://github.com/Behat/Sy...
But at the end, the process is the same, you have to fetch the "EntityManager", call persist on the user's object, and finally call "$em->flush()"
Cheers!
ok here I get this error:
┌─ @BeforeSuite # FeatureContext::bootstrapSymfony()
│
╳ There is no extension able to load the configuration for "swiftmailer" (in app/config/config_test.yml). Looked for namespace "swiftmailer", found "framework", "security", "twig", "monolog", "doctrine", "sensio_framework_extra", "knp_markdown", "doctrine_cache", "doctrine_migrations", "debug", "web_profiler", "sensio_distribution", "doctrine_fixtures" (Symfony\Component\DependencyInjection\Exception\InvalidArgumentException)
after adding:
/**
* @BeforeSuite
*/
public static function bootstrapSymfony(){
require_once __DIR__.'/../../app/autoload.php';
require_once __DIR__.'/../../app/AppKernel.php';
$kernel = new AppKernel('test', true);
$kernel->boot();
self::$container = $kernel->getContainer();
}
$user = new \AppBundle\Entity\User();
$user->setUsername($username);
$user->setPlainPassword($password);
$user->setRoles(array('ROLE_ADMIN'));
$em = self::$container->get('doctrine')->getManager();
$em->persist($user);
$em->flush();
I think something with new AppKernel ?
Hey Daka,
Hm, looks like Swiftmailer bundle is not enabled for test environment. Do you enable it for all environment or only for test in AppKernel.php?
Cheers!
Hi, very interesting tutorial!
However I have a question:
Why not to use KernelAwareContext offered by Behat Symfony2Extension?
Implementing then
you have the Symfony Kernel available along the Context Class.
Thanx
Hey Stefano,
Nice catch! Well, it's just due to teaching purposes. It's one of the possible ways to bootstrap Symfony kernel, actually, we show what exactly Symfony2Extension do behind the scene. But you're right, your way is simpler. And we show the example you mentioned in the next chapter, see https://knpuniversity.com/s... - but we use KernelDictionary trait instead, which is even more simple than implementing KernelAwareContext ;)
Cheers!
Thank you Victor, KernelDictionary is interesting too!
In order for the User class to be recognized I had to use "$user = new \AppBundle\Entity\User();"
Hey Shaun!
Actually, what you have will *definitely* work (as you know). What you don't see in my example is that (thanks to PhpStorm) as soon as I auto-complete the User class, it added a "use AppBundle\Entity\User" to the top of the class. So if you have that "use" statement, you can have the short version like mine. But, both work :).
Cheers!
Fatal error: Class 'AppBundle\Entity\User'
This is the error i receive although i used "use AppBundle\Entity\User; " at the top. Any idea?
Hey Victor,
It's not entirely clear what error, I suppose you trimmed it in the most interesting place :) Is it "Fatal error: Class 'AppBundle\Entity\User' not found"? Or is it a different error like you have invalid syntax/missing semi-colon/misprint in that class. So it depends. Please, double check that AppBundle\Entity\User class doesn't have syntax problem - PhpStorm could help with it. Also, does that class have "namespace AppBundle\Entity;"? Is class name "User"? Does this class have src/AppBundle/Entity/User.php path in your file system? Also look closer at letter case.
Cheers!
"Houston: no signs of life"
Start the conversation!