Created
February 7, 2021 15:30
-
-
Save mentisy/7cf812d63eaed79428a17d7467d5cf70 to your computer and use it in GitHub Desktop.
Mocking tables integration test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Test\TestCase\Command; | |
use Cake\TestSuite\ConsoleIntegrationTestTrait; | |
use Cake\TestSuite\TestCase; | |
/** | |
* App\Command\DeleteMemberCommand Test Case | |
* | |
* @uses \App\Command\DeleteMemberCommand | |
*/ | |
class DeleteMemberCommandTest extends TestCase | |
{ | |
use ConsoleIntegrationTestTrait; | |
/** | |
* Test execute method | |
* Unsuccessfully delete member | |
* | |
* @return void | |
*/ | |
public function testExecuteUnsuccessfully(): void | |
{ | |
$this->getMockForModel('Members', ['delete'])->method('delete')->willReturn(false); | |
$this->exec('deleteMember', ['1']); | |
$this->assertOutputContains('Could not delete member'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Test\TestCase\Controller\Admin; | |
use App\Test\TestCase\Controller\Traits\AuthTestTrait; | |
use Cake\TestSuite\IntegrationTestTrait; | |
use Cake\TestSuite\TestCase; | |
/** | |
* App\Controller\Admin\slangController Test Case | |
*/ | |
class SlangControllerTest extends TestCase | |
{ | |
use IntegrationTestTrait; | |
/** | |
* Test delete method | |
* Failure saving | |
* | |
* @return void | |
* @throws \Throwable | |
*/ | |
public function testDeleteFailure() | |
{ | |
$model = $this->getMockForModel('Slang', ['delete']); | |
$model->expects($this->once()) | |
->method('delete') | |
->will($this->returnValue(false)); | |
$this->delete(['controller' => 'slang', 'action' => 'delete', 1, 'prefix' => 'Admin']); | |
$this->assertFlashMessage(__('The slang could not be deleted. Please, try again.')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment