FAQ Database Discussion Community

## PhpStorm : Error in argument 1, char 2: option not found S

php,phpunit,phpstorm
So PHPstorm is running the PHP code fine in its console when I click run; that's great but I want to see it in the browser. So, I created a Built in Server inside project. Now, when I clicked on Run -> Run Project, I'm getting error as: "Error in...

## PHPunit call magic methods

methods,mocking,phpunit,magic-methods
I have magic method getData. Is it possible to call following inside unit test: $this->attributeMock ->method('getData') ->with('additional_data') ->willReturn('some value');$this->attributeMock ->method('getData') ->with('is_default') ->willReturn('something'); When I do this, I got: Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'is_default' +'additional_data' Is there some another way?...

## Travis CI is not case-sensitive by default?

filesystems,phpunit,composer-php,travis-ci,case-sensitive

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

php,selenium,selenium-webdriver,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...

## best way to mock a global static method

php,unit-testing,testing,phpunit

php,phpunit

## 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,...

## 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....

## mocking findOneBy“field” in doctrine2 with phpunit

php,unit-testing,doctrine2,mocking,phpunit

## 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...

zend-framework,phpunit

## 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 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...

## 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 overwrite actual method with stub

php,unit-testing,mocking,phpunit,stub

## Testing PHPUnit to test a “__construct() must be an instance of ..” does not recognize exception

php,phpunit
I have the following code to test if the class constructor will fire the exception but PHPUnit test fail on it. I am trying to figure out what I am doing wrong. /** @test */ public function should_require_instance_of_uuid() { $this->setExpectedException('Exception');$id = new BusinessPartnerId; } PHPunit gives the following error:...

## 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...

## 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...

## 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...

## 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 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...

## 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....

## Cannot connect to DB when setting up Codeception

php,mysql,pdo,phpunit,codeception

## 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...

## 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 Laravel Model::increment() with Mockery

php,laravel,phpunit,codeception,mockery

## 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...

## PHPUnit The current node list is empty

php,symfony2,testing,phpunit
I am creating some functional tests to test my controller. I have 2 functions at the moment. 1 for loggin in and 1 for the entity life cycle. both should run normally (I guess). Yet I am getting the following error: The current node list is empty I tried removing...

## PHPUnit ZF2 InputFilter with Custom Validator

zend-framework2,phpunit

## Should I create extra functions to make my code testable?

php,unit-testing,testing,phpunit
I am creating an application which depending on the day that it runs, it creates different reports. So if it is Monday @ 1am, It will create a weekly report, if it is the 1st of the month @ 1.30am, it will create a monthly report. My initial approach uses...

## PHPUnit symfony2 faking parameters.yml

symfony2,phpunit
I need to test some functionality with PHPUnit. I got isolated database for running tests but still some functionality depends on the parameters.yml where I add user IDs or IP addresses. Is there any way of creating fake parameters.yml for tests?

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

wordpress,phpunit,composer-php

## 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...

## 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 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 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.

## 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....

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

php,symfony2,phpunit,functional-testing

## 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...

## 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...

## Phpunit can't find abstract class

php,unit-testing,phpunit
For some reason when I try to test abstract class I get PHPUnit_Framework_MockObject_RuntimeException: Class "AbstractClass" does not exist. Here's the code AbstractClass.php <?php namespace SD\Project; abstract class AbstractClass { public function handle() { } } AbstractClassTest.php <?php require_once 'AbstractClass.php'; use SD\Project\AbstractClass; class AbstractClassTest extends PHPUnit_Framework_TestCase { public function testHandle() {...

## Vagrant: executable files are not executable

laravel,phpunit,puppet,laravel-5

## How to setup a mocked WP_Query in a WP_UnitTestCase

php,wordpress,phpunit

## Behat and Symfony data fixtures

php,symfony2,phpunit,fixtures,behat
I'm wondering is it possible to use separate database for the Behat tests? is there any way to drop and truncate database and load data fixtures with it like you can do with PHPUnit?