phpunit

Mockery fails with 'Could not load mock … class already exists' when running with --code-coverage

帅比萌擦擦* 提交于 2020-07-20 07:10:20
问题 I am trying to mock a class for phpunit. Php unit fails with the error Could not load mock ... class already exists . This is the only test I'm running, so it can't be the case that the class is mocked already. Any suggestion would be appreciated. Here is the error case: namespace Tests\Feature; use Tests\TestCase; class DeactivateACSTest extends TestCase { public function testDeactivateAcs() { $deviceController = \Mockery::mock('overload:App\Http\Controllers\Cloud\DeviceController');

Mockery fails with 'Could not load mock … class already exists' when running with --code-coverage

☆樱花仙子☆ 提交于 2020-07-20 07:10:11
问题 I am trying to mock a class for phpunit. Php unit fails with the error Could not load mock ... class already exists . This is the only test I'm running, so it can't be the case that the class is mocked already. Any suggestion would be appreciated. Here is the error case: namespace Tests\Feature; use Tests\TestCase; class DeactivateACSTest extends TestCase { public function testDeactivateAcs() { $deviceController = \Mockery::mock('overload:App\Http\Controllers\Cloud\DeviceController');

How to Determine if PHPUnit Tests are Running?

痴心易碎 提交于 2020-07-17 07:14:44
问题 I currently have a problem that I have to work around in legacy code to get our interaction with a PHP Extension to work properly (Singleton Testing Question). As such, I do not want to execute this code when running our normal production code with the application. Therefore, I need to check in regular PHP code if the code being executed is being executed as part of a test or not. Any suggestions on how to determine this? I thought about a defined variable tied to the presence of the test

Symfony2 access private services in tests

一个人想着一个人 提交于 2020-07-06 13:02:06
问题 Currently I'm working on testing some services in Symfony2 and I'm trying to use Guzzle MockPlugin for controlling CURL responses. Symfony version 2.3.8 is used. I've got to an interesting behaviour and I'm not sure if this is a Symfony2 bug or not. I have these services in services.yml: lookup_service_client: class: FOO public: false factory_service: lookup_client_builder factory_method: build lookup_repository_auth_type: class: AuthType arguments: ["@lookup_service_client"] lookup

Running PHPUnit in Intellij with docker remote interpreter from docker-compose expects project in “/opt/project”

北慕城南 提交于 2020-06-28 04:20:13
问题 I have a PHP symfony project loaded in IntelliJ (2019.3.2, Build #IU-193.6015.39) with the following structure (left out irrelevant files like README, etc): <project_root> +- src/ +- tests/ +- vendor/ | +- autoload.php +- .env +- composer.json +- composer.lock +- docker-compose.yml +- Dockerfile +- phpunit.xml +- phpunit-custom.xml The project interpreter is set to use remote docker (Docker for Mac) by docker-compose and IntelliJ detects the interpreter and debugger correctly: docker-compose

Method Illuminate\Auth\RequestGuard::logout does not exist Laravel Passport

点点圈 提交于 2020-06-22 22:52:09
问题 Am using Laravel Passport to build an API, I removed the web routes and its guard accordingly How can I test user logout? This is what I have so far: Logout Test /** * Assert users can logout * * @return void */ public function test_logout() { // $data->token_type = "Bearer" // $data->access_token = "Long string that is a valid token stripped out for brevety" $response = $this->json('POST', '/api/logout', [], [ 'Authorization' => $data->token_type . ' ' . $data->access_token ]); $response-

Method Illuminate\Auth\RequestGuard::logout does not exist Laravel Passport

流过昼夜 提交于 2020-06-22 22:51:48
问题 Am using Laravel Passport to build an API, I removed the web routes and its guard accordingly How can I test user logout? This is what I have so far: Logout Test /** * Assert users can logout * * @return void */ public function test_logout() { // $data->token_type = "Bearer" // $data->access_token = "Long string that is a valid token stripped out for brevety" $response = $this->json('POST', '/api/logout', [], [ 'Authorization' => $data->token_type . ' ' . $data->access_token ]); $response-

How do I test for an exact Exception message, rather than a substring, with PHPUnit?

谁说我不能喝 提交于 2020-06-08 16:52:44
问题 According to the PHPUnit Documentation on @expectedExceptionMessage , the string must only be a substring of the actual Exception thrown. In one of my validation methods, an array item is pushed for each error that occurs, and the final Exception message is displayed by imploding the array of errors. class MyClass { public function validate($a, $b, $c, $d) { if($a < $b) $errors[] = "a < b."; if($b < $c) $errors[] = "b < c."; if($c < $d) $errors[] = "c < d."; if(count($errors) > 0) throw new

How do I test for an exact Exception message, rather than a substring, with PHPUnit?

谁说胖子不能爱 提交于 2020-06-08 16:51:42
问题 According to the PHPUnit Documentation on @expectedExceptionMessage , the string must only be a substring of the actual Exception thrown. In one of my validation methods, an array item is pushed for each error that occurs, and the final Exception message is displayed by imploding the array of errors. class MyClass { public function validate($a, $b, $c, $d) { if($a < $b) $errors[] = "a < b."; if($b < $c) $errors[] = "b < c."; if($c < $d) $errors[] = "c < d."; if(count($errors) > 0) throw new

How to unit test the methods of a class whose constructor take some arguments?

匆匆过客 提交于 2020-05-26 01:22:31
问题 I have a class of form something like this: class A{ public function __constructor(classB b , classC c){ // } public function getSum(var1, var2){ return var1+var2; } } My test case class is something like this: use A; class ATest extends PHPUnit_Framework_TestCase{ public function testGetSum{ $a = new A(); $this->assertEquals(3, $a->getSum(1,2)); } } However when I run the phpunit, it throws some error like: Missing argument 1 for \..\::__construct(), called in /../A.php on line 5 Even if I