FAQ Database Discussion Community

## assertEqual not works when testing equals of command output

php,unit-testing,symfony2,phpunit,command-line-interface
Here is what I output in my command: $output->writeln("\033[37;42m Translations from " .$input->getArgument('bundle') . " imported successfully! \033[0m"); Here is what I get in command line with trim func to delete spaces: trim($commandTester->getDisplay()) ..string(69) " Translations from AcmeDemoBundle imported successfully! " But when I run this:$this->assertEquals(" Translations from...

## how to mock parent::xxx method

php,phpunit,mockery
Is there a way? class AAA extends BBB { public function ccc() { parent::ccc(); } } I want to check parent ccc method 1 time called...

## database restore for integration tests with phpunit

php,testing,phpunit,integration-testing
I'm using phpunit and I'd like to know if there is a correct form for restoring the database before running integration tests. At the moment I'm calling an sql server script with php exec() on the testcase setUp method, but don't know if this is the best choice class...

## Unit Testing a PHP Script

php,unit-testing,phpunit
I have some php scripts that are run as cronjobs. No classes and only a few functions. Id like to test the script with PHPUnit to make sure everything is working but it appears I need to rewrite the php as a class, which I dont want to do (or...

## Mockery object argument validation issue

php,phpunit,mockery
Consider the example classes (apologies for it being so convoluted, but it's as slim as possible): class RecordLookup { private $records = [ 13 => 'foo', 42 => 'bar', ]; function __construct($id) { $this->record =$this->records[$id]; } public function getRecord() { return$this->record; } } class RecordPage { public function...

## Graphical representation of test results of phpunit

phpunit,report,summary,phing
I am using phpunit to do functional tests. I use the log-junit option to generate results in JUnit-XML format. I then use phing to read this XML and generate a HTML report. The report is fine and neat. However, I have two questions:-- Can I also show the results in...

## How to setup phpUnit in Atlassian Bamboo?

php,phpunit,bamboo
I am new to Atlassian Bamboo. I have my code on Atlassian Stash Repository, and I want to run PhpUnit test on my code using Bamboo plan. I have go through documentation but I am not able to create one. Does anyone knows about it?

## Checking for a table row using DomCrawler

symfony2,dom,phpunit,domcrawler
I am writing a phpunit test... on my page I have several rows, one of them is like this: <tr><td>MATCH<small><span class="glyphicon glyphicon-pushpin"></span></small></td></tr> Some are like this: <tr><td>NOT A MATCH 1</td></tr> <tr><td>NOT A MATCH 2</td></tr> <tr><td>NOT A MATCH 3</td></tr> how can I run a test to check that the row with...

## Test cases to test a function phpunit

php,unit-testing,phpunit
I'm new to php unit testing, What are the valid test cases for below function. protected function validateParams($graph,$start, $destination) { if (!is_object($graph)) { throw new \InvalidArgumentException('Graph param should be an object !'); } if (empty($start)) { throw new \InvalidArgumentException('Start param is empty !'); } if (empty($destination)) { throw new...

## Have to run my script twice?

php,bash,phpunit
I wrote a script that walks through each directory, while ignoring some, and does a composer install, phpunit and should work, for the most part it does - When i run it a second time ... The issue is the phpunit command. The script comes to that command and prints...

## “Unable to locate element” error without sleep instruction

php,selenium,selenium-webdriver,phpunit

## Phpunit coverage: what is the difference between 'addUncoveredFilesFromWhitelist' and 'processUncoveredFilesFromWhitelist' options?

php,phpunit
I'm trying to set up code coverage for phpunit for a particular directory. Can someone tell me what is the difference between: <filter> <whitelist> <directory suffix=".php">lib/</directory> </whitelist> </filter> and <filter> <whitelist addUncoveredFilesFromWhitelist="true"> <directory suffix=".php">lib/</directory> </whitelist> </filter> and <filter> <whitelist processUncoveredFilesFromWhitelist="true"> <directory...

## Adding PHPUnit to an existing Cakephp 2.0

cakephp,phpunit
Does anyone know how to add PHPUnit to an existing CakePHP 2.0 project that wasn't created using composer? I am trying to add PHPUnit to an existing CakePHP 2.0 project that wasn't created with composer and I cannot get CakePHP to see that PHPUnit is installed. I am using a...

## Stubbing a method in php

php,mocking,phpunit,stubbing
I have an issue where I don't know how to say, when x is called, it expects y to be called at least once and I don't care what y does, so long as its called. So if we look at this example: public static function createAction($params) {$postParams =...

## Define type for PHPUnit's mock objects

php,phpunit,phpdoc
I was wondering if its possible to use phpdoc to define some object in specific scope (inside a method only) as PHPUni's Mock, so in that method i can take advantage of type-hints, such as ->expected, ->methods and so on, just like when you just create the mock without addressing...

## Mocking service with PHPUnit in Zend Framework 2

php,unit-testing,zend-framework2,phpunit

## Argument 1 passed to Foo::__construct() must be an instance of Psr\Log\LoggerTrait, instance of Mock_Trait_LoggerTrait_65811a25_bdddd884 given

php,unit-testing,mocking,phpunit,trait
I'm trying to mock a simple trait with PHPUnit but it is resulting on a FatalError, it works if I remove the type hinting: Argument 1 passed to Foo::__construct() must be an instance of Psr\Log\LoggerTrait, instance of Mock_Trait_LoggerTrait_65811a25_bdddd884 given The class: use Psr\Log\LoggerTrait; class Foo { /** * @var LoggerTrait...

## How can I make PHPUnit ignore a file pattern?

php,zend-framework2,phpunit
I'm doing Code Coverage reports for a project and there's a ton of files that are included or required while tests are running that are not actually required to be tested or added to coverage reports (I'm using Zend Framework 2; config + Module files are the culprit here). Is...

php,phpunit

## Why is PHPUnit still failing on SQL error, even though I have caught the exception

php,database,phpunit
I am trying to build a wrapper class that simplifies SQL access within my application (amongst other things). When testing my class with PHPUnit, a SQL error kills the test and spits out the error message to the console despite the fact that I have caught and handled the exception....

## PHPUnit overwrite actual method with stub

php,unit-testing,mocking,phpunit,stub

## PHPunit expectation on Mock object is not fulfilled

php,mocking,phpunit,expectations
Here is my class: public function __construct(Manager $moduleManager, Source\Yesno$yesNo) { $this->moduleManager =$moduleManager; $this->yesNo =$yesNo; } public function my1() { $this->moduleManager->isOutputEnabled('');$this->yesNo->toOptionArray(); } public function my2() { $this->moduleManager->isOutputEnabled('');$this->yesNo->toOptionArray(); } Here is my test: ... $this->observerMock =$this->getMock( 'path\to\Observer', null, [$this->moduleManagerMock,$this->yesNoMock], '', true ); ......

## Configuring PhPUnit.phar with Atlassian Bamboo

php,unit-testing,phpunit,bamboo,atlassian
I am trying to configure PHPUnit with bamboo. I have followed all the instruction available on Bamboo Documentation about Getting started with PHP and Bamboo accordingly but I am not able to get a successful build. Here are the screen shots of my configuration panel and Error log. My Task...

## Symfony2 unit tests produces Fatal Error: Declaration of ContainerAwareEventManager::removeEventListener() must be compatible with

unit-testing,symfony2,controller,phpunit,fatal-error
When calling phpunit on a very simple standard test, it produces the following output and error: Command (in symfony2 root): phpunit -c build/ src Output: PHPUnit 4.1.6-6-g43914fa by Sebastian Bergmann. Configuration read from /srv/xxxxxxxxx/build/phpunit.xml PHP Fatal error: Declaration of Symfony\Bridge\Doctrine\ContainerAwareEventManager::removeEventListener() must be compatible with Doctrine\Common\EventManager::removeEventListener($events,$listener = NULL) in...

## Cannot Change Method Name in PHPUnit

php,methods,phpunit,naming
I am running PHPUnit 4.2.2 inside a local Composer install. I'm also running PHP CodeSniffer 2.2.0. I have written this unit test: <?php include_once 'animals/Cat.php'; class CatAgeTest extends PHPUnit_Framework_TestCase{ public function testTrueIsTrue(){ $kittyAgeTest = new Cat("steak");$result = $kittyAgeTest->getAge() >=5 &&$kittyAgeTest->getAge() <= 10; $this->assertTrue($result); } } ?> It passes,...

## phpUnit: Pass argument into tearDownAfterClass from a test

php,phpunit
I'm using phpUnit. Is it possible to pass a result from another test to the tearDownAfterClass. I know it's possible to use @depends to make other tests depend on a test for data. Is it possible to pass that data to tearDownAfterClass afterwards somehow. @depends doesn't seem to work for...

## How to test specific methods with PHPUnit

php,class,unit-testing,methods,phpunit
I need help with PHPUnit and some methods. How should you guys write tests in PHPUnit to reach a high code coverage for the following properties and methods? I'm pretty new to PHPUnit and could need some help. I've just write some test cases for more basic code. This class...

symfony2,phpunit
I need to test behavior of the feature which depends on the users IP address. The user should be redirected to different pages depending on his IP address. I create client like that: $this->client = static::createClient(); Is there any way to do that?... ## Phpunit yii: two fixtures to one table yii,phpunit In phpunit, with Yii, is possibile to create more fixtures for the same table? I would like to have different fixtures folders to be used with different unit test, to avoid problems between the various test file. ## PHPUnit Mysteriously Fails On Object Constructor with require_once and$SERVER variable

php,netbeans,phpunit
I'm trying to wrap a test class around a pre-existing PHP class file that does not adhere to any PSR standard. The PHP object I'm trying to test has a constructor that accepts 1 argument. When prepping my object in setUp, my test correctly fails because there is a constructor...

## Getting More Context Around PHPUnit Test Failures

php,phpunit,automated-tests
In PHPUnit, let's say I do this: $this->assertTrue($some_variable == "foo" ); When I run my tests with my code in a failing state, PHPUnit tells me: Failed asserting that false is true. Which is all fine and good, and I can usually track down WHY the test is failing....

## phpunit testing expectedException not working

php,exception,phpunit
I am trying to test my class for InvalidArgumentException but I get Tests\BarTest::should_receive_parameter Missing argument 1 for Itdc\Foo\Bar::__construct(), called in /mypath/foo/tests/BarTest.php on line 10 and defined This is the test (BarTest.php) file I use: <?php namespace Tests; use Itdc\Foo\Bar; class BarTest extends \PHPUnit_Framework_TestCase { /** @test */ public function should_receive_parameter()...

## PHPunit no tests execute on Travis CI

php,phpunit,composer-php,travis-ci
I'm been following a PHPUnit tutorial for the first time and my tests run fine locally. However, when running my tests on Travis CI, no tests are executed and my build exits with 0. My directory structure and full code can be seen on the repo. Build log from Travis...

## PHPUnit: Calling a child method from abstract class constructor

phpunit
I'm seeing an unexpected (to me) behaviour with PHPUnit, is this a bug, or am I doing something wrong? Simplified test case: abstract class abstractSpeaker { public function __construct($param) {$this->setSpeaker($param);$this->getSpeaker()->speak(); //bad line, causes error $this->tellSpeakerToSpeak(); //this lines ok } abstract function setSpeaker($value); abstract function getSpeaker(); function tellSpeakerToSpeak() {...

## How can I test a function that uses DateTime to get the current time?

unit-testing,symfony2,datetime,phpunit,mockery
Most of the answers I have seen on StackOverflow are without using the DateTime object, and are instead using the date() function. This makes them very dirty solutions (overriding date(), mocking a protected function of the subject under test, etc). Is there a way to mock DateTime, effectively mocking the...

## How To Write Acceptance Tests for Internet Explorer with: Selenium, PHPUnit and Mac OS X?

osx,internet-explorer,selenium,phpunit,acceptance-testing
I'm trying to write acceptance tests for a project using multiple browsers. All the tests run fine with: Firefox, Chrome and Safari. However, I don't know how to run them in Internet Explorer. I use: PHPUnit, Selenium and Mac OS X. I also use VirtualBox with Windows 8 and Windows...

## Laravel 5.1 Unable to Run Test on User Password Mutator

php,unit-testing,laravel,phpunit,laravel-5.1
I have a password mutator: /** * Mutator for setting the encryption on the user password. * * @param $password */ public function getPasswordAttribute($password) { $this->attributes[ 'password' ] = bcrypt($password); } That I'm trying to test: /** * A basic check of password mutator. * * @return void */ public...

## PHPUnit: Testing RestFul API with die response

php,json,api,zend-framework2,phpunit

## Can't run tests provided in Slim Framework

php,xampp,phpunit,netbeans-8,slimframework
I'm trying to make a simple rest client for my android app. I would like to do than in TDD way, but for that I need simple working configuration for all actions (GET, POST, and so on). After some struggling I was able to make test work with get requests....

## How to unit test a data extraction method

php,unit-testing,phpunit
I have created a method which interacts with a framework, pulling out order items which have a completed status. However, how can I unit test my method to ensure it behaves correctly... class A { public function extractData() { // extract data from framework $dataCollection = FrameworkX->getDataCollection('sales/orders');$dataCollection->filter('state', 'complete'); return...

## Mocking Laravel Model::increment() with Mockery

php,laravel,phpunit,codeception,mockery

## Mockery mock method inside closure

unit-testing,laravel-4,mocking,phpunit,mockery
I have problem unit testing method inside closure called by call_user_func() example : public function trans($lang,$callback) { $this->sitepress->switch_lang($lang); call_user_func($callback); } on controller : public function sendMail() {$foo = $baz = 'something';$mail = $this->mailer;$this->helper->trans_c('en', function() use($foo,$baz, $mail) {$mail->send('Subject', $foo,$baz); }); } test case :...

## How to use group in phpunit?

zend-framework,phpunit
How to invoke phpunit for zendframework module group wise. I mean when you invoke phpunit then it invoke module1 first then module2 and so on.

## PHPUnit RabbitMQ: write test for create connection function

php,phpunit,rabbitmq
I'm facing the following problem. I've wrote a function that create a connection object (AMQPConnection) given the required parameters. Now I want to write the corresponding unit test. I just don't know how to do it without having the RabbitMQ broker running. Here is the function in question: public function...

## Mocking or not registry-like object in phpunit tests

unit-testing,mocking,phpunit

php,phpunit

## Unable to find wrapper when testing Guzzle call with PHPUnit

php,codeigniter,phpunit,guzzle
I am writing a unit test for an API that I am developing. The API is written in the Codeigniter framework, that calls another API using Guzzle. The test I am writing verifies that the API call returns the correct response. The Test.php file contains the following code require '/application/libraries/apiWrappers/Breathehr.php';...

## Get container in test class Symfony2

php,unit-testing,symfony2,phpunit,containers
how I can get container to be able getting mys services in tests classes. I found the solution to require_once dir(__FILE__). '/...../AppKernel.php;, But when I go into WebTestCase class and found protected static function createClient(array $options = array(), array$server = array()) { static::bootKernel($options);$client = static::$kernel->getContainer()->get('test.client');$client->setServerParameters($server); return$client;...

## Functional testing in Symfony2 gives me error: Failed asserting that false is true

php,symfony2,phpunit,functional-testing

## How to setup a mocked WP_Query in a WP_UnitTestCase

php,wordpress,phpunit

## Many test cases to cover a function - phpunit

php,unit-testing,symfony2,phpunit
For the following function I need to write more test cases, I have already written one, can someone give some ideas, Perhaps to test return values of intermediate function calls. public function calculateShortestPath($graphObj,$start, $destination) {$shortestPath = null; if ($this->validateParams($graphObj, $start,$destination) == true) { $result =$this->getAllVerticesAndNeighbours($graphObj);$vertices...

## PHPUnit mock using mock

php,dependency-injection,mocking,phpunit,unit-testing
I have two class, i want to test it via PHPUnit. But something i do wrongly at mocking the stuffs. I want to altering a method what called by the first class. class One { private $someVar = null; private$abc = null; public function Start() { if ( null...

## WP_UnitTestCase - how to configure the include_path correctly with phpunit PHAR

wordpress,phpunit,composer-php

## PhpUnit Testing stub method multiple return

php,symfony2,phpunit
I am doing some PHPUnit testing with symfony2. I am having a problem with one particular test. I am testing a response form one of my Class of course one response is true one false. I have a Mock of my Database and I have a stub for one of...

## Zendframework(1.12.11) view helper not found in phpunit

zend-framework,phpunit

## Access phpunit group parameter inside bootstrap

php,phpunit,bootstrap
I am using phpunit to test a large php project. The tests are organised in groups using @group annotation. I also have a phpunit.xml file in the root directory of my tests, which, among other things, specifies the bootstrap php file. In that file, I perform some general initialisation before...

## Can't run phpunit tests from command line

php,phpunit,laravel-5
I am trying to run unit tests in a new laravel 5 application, using the phpunit framework. In the root path of my laravel application I ru the following command: ./vendor/bin/phpunit /tests/ExampleTest.php And then I get the following message: You need to set up the project dependencies using the following...

## Cakephp 3 - MissingDatasourceConfigException when running phpunit test

php,unit-testing,cakephp,phpunit,cakephp-3.0
I am trying to run some unit tests in CakePHP 3 with PHPUnit 4.7.3, but I`m getting the following error: PHPUnit 4.7.3 by Sebastian Bergmann and contributors. There was 1 error: 1) App\Test\TestCase\Model\Table\MoviesTableTest::testFindMoviesByGenre Cake\Datasource\Exception\MissingDatasourceConfigException: The datasource configuration "default" was not found. C:\xampp\htdocs\movie-pal\vendor\cakephp\cakephp\src\Datasource\ConnectionManager.php:188 C:\xampp\htdocs\movie-pal\vendor\cakephp\cakephp\src\ORM\TableRegistry.php:191...

## Phpunit permission test

php,testing,phpunit
I have function that take a csv file and generate file content in array. I need to write a phpunit tests. Goal is represend correctness of behavior when input is not present or unreadable (whether because the file is malformed or due to the lack of sufficient access rights). I...

## How to back to window after closed frame with Selenium and PHPUnit?

php,selenium,selenium-webdriver,phpunit

## Symfony 2 Functional test

php,symfony2,phpunit,functional-testing
I encounter an issue which doesn't make much logic to me in one of my functional tests. The test is quite simple, it just requests for the homepage, and searches for an element with a certain class in it. The homepage is for a blog that displays a list of...

## PHPUnit: “Class 'Eloquent' not found” when using @dataProvider

php,laravel,phpunit,composer-php
I'm running into an issue when writing unit tests with PHPUnit using @dataProvider in a Laravel app. The error I'm receiving is: PHP Fatal error: Class 'Eloquent' not found in /path/to/project/app/models/ExampleClass.php on line 7 It looks like the constant used in the dataProvider is causing the fatal. composer.json: "psr-4": {...