loadsys / loadsys/CakePHP-Skeleton

Provide Easy Mocking For Cake3 Table Classes

Open
#140 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.x enhancement
Dominant language
PHP
Stars
10
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Create a Trait that provide a getTableMock($tableName, $methodsToMock = []) method.

Maybe also create a class that extends IntegrationTestCase that pulls that trait in by default.

This is the basic flow to mock a Table Class for a Controller Structure.

$connection = \Cake\Datasource\ConnectionManager::get('test');
$config = ['connection' => $connection];

$UsersTable = $this->getMock(
    'App\Model\Table\UsersTable',
    ['save'],
    [$config]
);

$UsersTable->expects($this->once())
    ->method('save')
    ->will($this->returnValue(false));

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the CakePHP 3 test setup and the shown getMock flow for a Table class. Determine whether the requested getTableMock($tableName, $methodsToMock = []) trait alone is sufficient or whether an IntegrationTestCase subclass is also needed; done means the example controller-testing flow can mock a Table class and configure method expectations.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.