Skip to content

Instantly share code, notes, and snippets.

@mentisy
Created February 7, 2021 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mentisy/7cf812d63eaed79428a17d7467d5cf70 to your computer and use it in GitHub Desktop.
Save mentisy/7cf812d63eaed79428a17d7467d5cf70 to your computer and use it in GitHub Desktop.
Mocking tables integration test
<?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');
}
}
<?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