selenium testing in cakephp with phpunit - php

I want to learn about ui testing with selenium in phpunit. I had phpunit installed on my cakephp project, and it was running perfectly. Then I decided to install selenium following the steps described in https://phpunit.de/manual/3.7/en/selenium.html (i installed selenium in my project with the following command $ php composer.phar require --dev phpunit/phpunit-selenium: ">=1.2". Now after starting the selenium server with its jar file, I have been trying to run the example test provided in the link above, but I am receiving the following error:
$ vendor/bin/phpunit
PHP Fatal error: Class
'PHPUnit_Framework_TestCase' not found in
/var/www/html/ujols/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php
on line 97
Seems like the error is related to the Selenium2TestCase.php file that was installed with the composer. This is how the Selenium2TestCase.php file starts:
abstract class PHPUnit_Extensions_Selenium2TestCase extends PHPUnit_Framework_TestCase
{
Is there anyone here who managed to install selenium on cakephp or any other php framework? I would be super grateful if you could help me fix the problem
EDIT the sample test case i ve been trying to run to check if selenium is working:
PlainviewTest.php
<?php
class WebTest extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
$this->setBrowser('firefox');
$this->setBrowserUrl('http://www.example.com/');
}
public function testTitle()
{
$this->url('http://www.example.com/');
$this->assertEquals('Example WWW Page', $this->title());
}
}
?>

I figured a way to get selenium integrated with phpunit in my app with a lot of help from #ndm, here are the steps:
Follow the easy installation steps here - Testing with Selenium WebDriver + PHPUnit
*Make sure your new ui-tests are not in the same folder with unit tests, I had mine in the same folder and kept getting fatal errors.
*If running the ./vendor/bin/steward run staging firefox command returns an error, then change firefox to chrome. If you still keep getting error (like I did), install chromedriver and run again. It should work.
It was really worth all the effort.

Related

Namespace that seems it doesn't exist is working but why?

I have this exercice folder that gave me instructions on how to install the web application:
So this folder contains a .sh file that installs the necessary things:
npm install
curl -o phpunit -L https://phar.phpunit.de/phpunit-7.phar
chmod +x phpunit
./phpunit --version
So basically this adds a file called phpunit inside root folder. So by far I kind of understand what's going on, so this installs node dependencies and also installs phpunit (I think so), but this project has a test example unit:
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class HelloWorldTest extends TestCase
{
public function testWhenGetDataFromHelloWorld(): void
{
$this->assertEquals('Hello World', 'Hello World');
}
}
At this point is where I don't get how is use PHPUnit\Framework\TestCase; working, since I don't have any folder called PHPUnit, I get that use is something like importing a class, but still, how is this working (when I run the test it does not give me any kind of error)?, also, it appears that vscode detects the import as an error because it seems that it doesn't exist.
My file tree is as follows:
Can someone explain me, please?
This is because all the dependencies are in the phpunit-7.phar file, which was named phpunit by that script.
"The easiest way to obtain PHPUnit is to download a PHP Archive (PHAR) that has all required (as well as some optional) dependencies of PHPUnit bundled in a single file."
PHPUnit - Installing PHPUnit - PHP Archive (PHAR)

TestCase not found in KernelTestCase.php with Symfony 3.2.7

I'm having problems when running Symfony (PHPUnit integrated) tests in my server, it works as expected in my build host but when I upload them to Gitlab CI via Git it throws me the next error:
Class 'PHPUnit\Framework\TestCase' not found in /project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php on line 24
I tried executing phpunit, phpunit ., phpunit tests all with the same results
It was working until a few weeks ago.
My server Symfony version is 3.2.7 and the PHPUnit version is 4.2.6
PHPUnit version is 4.2.6 is very old, and does not contain any Namespaced classes. The Symfony KernelTestCase.php now uses those PHPUnit namespaces to pull on the TestCase class.
There is forward compatibility in PHPUnit 5.4.3, though v5.7, if not 6.0 would be better.
So, you'll want to upgrade your composer.json file and tests to use the new namespaces.

PHP Fatal error: Class 'Bllim\Datatables\DatatablesServiceProvider'

I'm a newbie in Laravel. I just cloned my co-worker git and try to php artisan list but it gives me error
PHP Fatal error: Class 'Bllim\Datatables\DatatablesServiceProvider' not found in /Users/path-to-project/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 157
I can't find any documentations about this error and search results don't really help.
Any of you ever met this problem and care to help me fix this? Thank you.
Asking your coworker would be a first good step :)
That said, the error you're getting indicates that PHP can't find or autoload a Laravel Service provider class. If your coworker is following Laravel best practices, you should be able to fix this by running the following command from your root project directory (or the directory with a composer.json file)
$ composer install
or ...
$ composer.phhar install
The format of the command (phar or no phar) will depend on how you've installed composer, the dependency/package manager used in Laravel.

PHPUnit with Symfony Fatal error: Class 'Doctrine\Bundle\DoctrineBundle\DoctrineBundle' not found

I'm trying to testing my app made with Symfony. I wrote a test and when I launch it, i get the following error:
Fatal error: Class 'Doctrine\Bundle\DoctrineBundle\DoctrineBundle'
not found in /.../app/AppKernel.php on line 17
I had the same error with Symfony's MonologBundle, AsseticBundle and SwiftmailerBundle: then I've manually added these bundles into my app, so pheraps I have fixed those errors, but with Doctrine I've not found any solutions yet.
It looks like maybe you did not install the Doctrine bundle.
Try to go to the root of your project where the composer.phar is located through a console, and try to run it like this:
php composer.phar
It will install all dependencies of Symfony2,and hopefully everything is going to work :)

PHPUnit_Util_Skeleton_Test not found in CakePHP

I'm able to run my individual tests for each model in a plugin called Agg, but when I try to run a CakeTestSuite, then I get an error.
class ModelsTest extends CakeTestSuite
{
public static function suite()
{
$suite = new CakeTestSuite('All model tests');
$suite->addTestDirectory(TESTS . 'Case' . DS . 'Model');
return $suite;
}
}
Running that suite generates this error.
Fatal error: Class 'PHPUnit_Util_Skeleton_Test' not found in C:\work\zend\cake\Cake\TestSuite\CakeTestSuiteCommand.php on line 77
I'm using PHP 5.3.15 and have PHPUnit 3.7.12 installed with CakePHP 2.2.5
I get this error when running tests both via the web and the CLI.
Any help would be appreciated.
UPDATE:
If I search for 'PHPUnit_Util_Skeleton_Test' in PEAR folder for PHPUnit it's not found. This seems strange to me. Am I using the wrong version of PHPUnit? When was this class introduced?
UPDATE:
It seems that this class is no longer used in PHPUnit 3.7.x, and I'm wondering if CakePHP 2.2 will only work with PHPUnit 3.6. I tried to uninstall the pear package, and then install the 3.6.x version but always installs the newest version. Any ideas on how to downgrade PHPUnit?
UPDATE:
Downgrading using the --force to install older versions of PHPUnit didn't resolve the problem. I tried 3.6.12, 3.6.5 and 3.5. With the 3.6.12 I got an error with is_file() somewhere in the PHPUnit code.
PHPUnit_Util_Skeleton_Test is available in PHPUnit 3.6, see https://github.com/sebastianbergmann/phpunit/blob/3.6/PHPUnit/Util/Skeleton/Test.php
I suggest uninstalling all phpunit packages and reinstalling phpunit 3.6 with
$ pear install phpunit/phpunit-3.6.12
It might be that dependencies were broken when downgrading the single phpunit package with --force, and this should fix it.

Categories