phpunit

PHPUnit - Don't fail when the dataProvider returns an empty array

谁说我不能喝 提交于 2019-12-23 12:01:11
问题 I have a PHPUnit test which uses a @dataProvider . The dataprovider checks the filesystem for certain files. However I'm using this test in different environments what means it can happen that the files do not exist. This means that the dataProvider does not find anything and that the test is not executed. And this causes the test run to end in a failure. Question: is the a way to configure PHPUnit to ignore tests which have providers that produce nothing? 回答1: While I do not know of any

Issue with the Entity Manager and phpunit in Symfony 2

戏子无情 提交于 2019-12-23 10:05:59
问题 I have an issue with my Entity Manager in phpunit. This is my test : public function testValidChangeEmail() { $client = self::createAuthClient('user','password'); $crawler = $client->request('GET', '/user/edit/30'); $crawler = $client->submit($crawler->selectButton('submit')->form(array( 'form[email]' => 'new@email.com', ))); /* * With this em, this work perfectly * $em = $client->getContainer()->get('doctrine.orm.entity_manager'); */ $user = self::$em->getRepository('MyBundle:User')-

mock atLeastOnce with concrete value, the rest not important

点点圈 提交于 2019-12-23 09:48:41
问题 The question is in PHP , but applies to any language using the xUnit framework. I want a mock, that expects 140 calls to method jump . I need to verify, that at least once there is a call with 500 as parameter. I don't care if all the calls are 500, but I need at least one that is called with 500. $mock = $this->getMock('Trampoline', ['jump']); $mock->expects($this->atLeastOnce()) ->method('jump') ->with($this->equalTo(500)) ->will($this->returnValue(true)); $sportsman->setTramploine($mock);

PHPUnit's TextUI/command.php not found

爱⌒轻易说出口 提交于 2019-12-23 09:39:30
问题 I installed phpunit for my symfony2 project following this: How to use phpunit installed from composer? But I get the following error now: Warning: include(C:\Program Files (x86)\Zend\Apache2\Program Files (x86)\Zend\Apache2\htdocs\project1\vendor\phpunit\phpunit\PHPUnit\TextUI\Command.php): failed to open stream: No such file or directory in C:\Program Files (x86)\Zend\Apache2\htdocs\project1\vendor\composer\ClassLoader.php on line 150 The file does exist and is in the autoload_classmap file

PHPUnit runs only from the command line. Why?

懵懂的女人 提交于 2019-12-23 09:37:12
问题 I have the following code: <?php class MyTest extends PHPUnit_Framework_TestCase { public function testCalculate() { $this->assertEquals(2, 1 + 1); } } ?> When I open the PHP file in the browser, I get the following error: Fatal error: Class 'PHPUnit_Framework_TestCase' not found However, if I use the command line it works fine: phpunit [local_path_here]/testcase.php Result: . Time: 0 seconds, Memory: 5.00Mb OK (1 test, 1 assertion) Why is that? How can I make it to run it in the browser as

Get environment inside controller

ⅰ亾dé卋堺 提交于 2019-12-23 09:33:06
问题 I have a situation in one of my controllers that should only be accessed via AJAX, I have the following code. if (!$request->isXmlHttpRequest()) { $response = new Response(); $response->setContent('AJAX requests only!'); return $response; } When I am testing this gives me an issue because the request hasn't actually been made via AJAX. This then breaks my tests every time. How should I go about working around this? My Ideas: I have tried to set a server header but have had absolutely no

Example PHPUnit Test on Laravel 5.4 fails with 404

≯℡__Kan透↙ 提交于 2019-12-23 08:29:30
问题 I can my project on Laravel 5.4 from link: localhost:8888/streaming_statistic/public I have a test: <?php namespace Tests\Feature; use Tests\TestCase; use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; class ApiTest extends TestCase { public function testBasicTest() { $response = $this->get('/'); $response->assertStatus(200); } } I run all tests with command ./vendor/bin/phpunit But

How to reduce the number of database connections in tests in PHPUnit and ZF3?

自古美人都是妖i 提交于 2019-12-23 07:27:23
问题 I'm writing integration/database tests for a Zend Framework 3 application by using zendframework/zend-test 3.1.0 , phpunit/phpunit 6.2.2 , and phpunit/dbunit 3.0.0 My tests are failing due to the Connect Error: SQLSTATE[HY000] [1040] Too many connections I set some breakpoints and took a look into the database: SHOW STATUS WHERE `variable_name` = 'Threads_connected'; And I've actually seen over 100 opened connections. I've reduced them by disconnecting in the tearDown() : protected function

How to reduce the number of database connections in tests in PHPUnit and ZF3?

六眼飞鱼酱① 提交于 2019-12-23 07:27:09
问题 I'm writing integration/database tests for a Zend Framework 3 application by using zendframework/zend-test 3.1.0 , phpunit/phpunit 6.2.2 , and phpunit/dbunit 3.0.0 My tests are failing due to the Connect Error: SQLSTATE[HY000] [1040] Too many connections I set some breakpoints and took a look into the database: SHOW STATUS WHERE `variable_name` = 'Threads_connected'; And I've actually seen over 100 opened connections. I've reduced them by disconnecting in the tearDown() : protected function

Hide output during PHPUnit test execution

僤鯓⒐⒋嵵緔 提交于 2019-12-23 07:13:09
问题 I have some var_dumps in my php code (i understand what there must be none in the end, but still), and while tests are running they outputs non necessary information to console, is there a method to ignore some code execution? I've tried /** * @codeCoverageIgnore */ and // @codeCoverageIgnoreStart print '*'; // @codeCoverageIgnoreEnd But this just ignores coverage, and still executes the code. 回答1: You can set the setOutputCallback to a do nothing function. The effect is to suppress any