Skip to content

Commit

Permalink
Merge pull request #999 from cakephp/3.next-phpunit
Browse files Browse the repository at this point in the history
Bump up CakePHP and PHPUnit.
  • Loading branch information
markstory authored Aug 8, 2024
2 parents 83d6d12 + e480275 commit ac26976
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 34 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
"require": {
"php": ">=8.1",
"brick/varexporter": "^0.5.0",
"cakephp/cakephp": "^5.0.3",
"cakephp/cakephp": "dev-5.next as 5.1.0",
"cakephp/twig-view": "^2.0.0",
"nikic/php-parser": "^5.0.0"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^5.0.0",
"cakephp/debug_kit": "^5.0.0",
"phpunit/phpunit": "^10.1.0"
"phpunit/phpunit": "^10.5.5 || ^11.1.3"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 2 additions & 1 deletion src/Command/AllCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
}

foreach ($tables as $table) {
$subArgs = new Arguments([$table], $options, ['name']);
$parser = $command->getOptionParser();
$subArgs = new Arguments([$table], $options, $parser->argumentNames());
$command->execute($subArgs, $io);
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/Command/TemplateAllCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ public function execute(Arguments $args, ConsoleIo $io): int
$scanner = new TableScanner($connection);

foreach ($scanner->listUnskipped() as $table) {
$templateArgs = new Arguments([$table], $args->getOptions(), ['name']);
$parser = $this->templateCommand->getOptionParser();
$templateArgs = new Arguments(
[$table],
$args->getOptions(),
$parser->argumentNames()
);

$this->templateCommand->execute($templateArgs, $io);
}

Expand Down
2 changes: 1 addition & 1 deletion src/View/BakeView.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function dispatchEvent(string $name, array $data = [], ?object $subject =
*
* @param ?string $plugin Optional plugin name to scan for view files.
* @param bool $cached Set to false to force a refresh of view paths. Default true.
* @return array<string> paths
* @return list<string> paths
*/
protected function _paths(?string $plugin = null, bool $cached = true): array
{
Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase/Command/ControllerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Cake\Console\Arguments;
use Cake\Console\CommandInterface;
use Cake\Core\Plugin;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* ControllerCommand Test
Expand Down Expand Up @@ -380,9 +381,9 @@ public static function nameVariations()
/**
* test that both plural and singular forms work for controller baking.
*
* @dataProvider nameVariations
* @return void
*/
#[DataProvider('nameVariations')]
public function testMainWithControllerNameVariations($name)
{
$this->generatedFile = APP . 'Controller/BakeArticlesController.php';
Expand Down
8 changes: 7 additions & 1 deletion tests/TestCase/Command/ModelCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Cake\Database\Driver\Sqlite;
use Cake\Database\Driver\Sqlserver;
use Cake\Datasource\ConnectionManager;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* ModelCommand test class
Expand Down Expand Up @@ -1971,8 +1972,13 @@ public function testBakeEntityFullContext()
public function testBakeEntityWithPropertyTypeHints()
{
$model = $this->getTableLocator()->get('TodoItems');
$model->associations()->removeAll();

$model->belongsTo('Users');
$model->hasOne('TodoReminders');
$model->hasMany('BakeTest.TodoTasks');
$model->hasMany('TodoLabels');

$model->getSchema()->addColumn('array_type', [
'type' => 'array',
]);
Expand Down Expand Up @@ -2383,9 +2389,9 @@ public static function nameVariations()
/**
* test that execute passes with different inflections of the same name.
*
* @dataProvider nameVariations
* @return void
*/
#[DataProvider('nameVariations')]
public function testMainWithNamedModelVariations($name)
{
$this->generatedFiles = [
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase/Command/SimpleBakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Bake\Test\TestCase\TestCase;
use Cake\Console\CommandInterface;
use Cake\Core\Plugin;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* SimpleBakeCommandTest class
Expand Down Expand Up @@ -148,6 +149,7 @@ public static function subclassProvider()
* @dataProvider subclassProvider
* @return void
*/
#[DataProvider('subclassProvider')]
public function testImplementations($class)
{
$task = new $class();
Expand Down
7 changes: 4 additions & 3 deletions tests/TestCase/Command/TemplateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Cake\Core\Plugin;
use Cake\Database\Type\EnumType;
use Cake\View\Exception\MissingTemplateException;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* TemplateCommand test
Expand Down Expand Up @@ -106,9 +107,9 @@ public function testController()
* Test the controller() method.
*
* @param string $name
* @dataProvider nameVariations
* @return void
*/
#[DataProvider('nameVariations')]
public function testControllerVariations($name)
{
$command = new TemplateCommand();
Expand Down Expand Up @@ -482,7 +483,7 @@ public function testBakeViewEnum()
public function testBakeViewEnumNoLabel()
{
$table = $this->fetchTable('Articles');
$table->getSchema()->setColumnType('status', EnumType::from(ArticleStatus::class));
$table->getSchema()->setColumnType('published', EnumType::from(ArticleStatus::class));

$this->generatedFile = ROOT . 'templates/Articles/view.php';
$this->exec('bake template articles view');
Expand Down Expand Up @@ -624,7 +625,7 @@ public function testBakeIndexWithEnumWithLabel()
public function testBakeIndexWithEnumNoLabel()
{
$table = $this->fetchTable('Articles');
$table->getSchema()->setColumnType('status', EnumType::from(ArticleStatus::class));
$table->getSchema()->setColumnType('published', EnumType::from(ArticleStatus::class));

$this->generatedFile = ROOT . 'templates/Articles/index.php';
$this->exec('bake template articles index');
Expand Down
7 changes: 4 additions & 3 deletions tests/TestCase/Command/TestCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Cake\Console\CommandInterface;
use Cake\Core\Plugin;
use Cake\Http\ServerRequest as Request;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* TestCommandTest class
Expand Down Expand Up @@ -291,9 +292,9 @@ public static function realClassProvider()
/**
* test that resolving class names works
*
* @dataProvider realClassProvider
* @return void
*/
#[DataProvider('realClassProvider')]
public function testGetRealClassname($type, $name, $expected)
{
$this->setAppNamespace('App');
Expand Down Expand Up @@ -659,9 +660,9 @@ public static function caseFileNameProvider()
/**
* Test filename generation for each type + plugins
*
* @dataProvider caseFileNameProvider
* @return void
*/
#[DataProvider('caseFileNameProvider')]
public function testTestCaseFileName($type, $class, $expected)
{
$this->setAppNamespace('App');
Expand Down Expand Up @@ -712,9 +713,9 @@ public static function mapTypeProvider()
/**
* Test that mapType returns the correct package names.
*
* @dataProvider mapTypeProvider
* @return void
*/
#[DataProvider('mapTypeProvider')]
public function testMapType($original, $expected)
{
$command = new TestCommand();
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use Bake\BakePlugin;
use Cake\Console\CommandCollection;
use Cake\Core\Plugin;
use Cake\Routing\RouteBuilder;
use Cake\Routing\RouteCollection;

Expand All @@ -44,6 +45,7 @@ public function testRoutes()

public function testConsoleDiscoverBakeCommands()
{
Plugin::getCollection()->add(new BakePlugin());
$commands = new CommandCollection();
$plugin = new BakePlugin();
$commands = $plugin->console($commands);
Expand Down
13 changes: 10 additions & 3 deletions tests/TestCase/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,25 @@ public function tearDown(): void
* Load a plugin from the tests folder, and add to the autoloader
*
* @param string $name plugin name to load
* @param bool $loadBake Whether or not to load the Bake plugin as well.
* @return void
*/
protected function _loadTestPlugin($name)
protected function _loadTestPlugin(string $name, bool $loadBake = false): void
{
$root = dirname(dirname(__FILE__)) . DS;
$path = $root . 'test_app' . DS . 'Plugin' . DS . $name . DS;

$this->loadPlugins([
$plugins = [
$name => [
'path' => $path,
],
]);
];

if ($loadBake) {
$plugins[] = 'Bake';
}

$this->loadPlugins($plugins);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Utility/TemplateRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function testGenerate()
*/
public function testGenerateWithTemplateOverride()
{
$this->_loadTestPlugin('TestBakeTheme');
$this->_loadTestPlugin('TestBakeTheme', true);
$renderer = new TemplateRenderer('TestBakeTheme');
$renderer->set([
'plugin' => 'Special',
Expand All @@ -89,7 +89,7 @@ public function testGenerateWithTemplateOverride()
*/
public function testGenerateWithTemplateFallbacks()
{
$this->_loadTestPlugin('TestBakeTheme');
$this->_loadTestPlugin('TestBakeTheme', true);
$renderer = new TemplateRenderer('TestBakeTheme');
$renderer->set([
'name' => 'Articles',
Expand Down
11 changes: 2 additions & 9 deletions tests/TestCase/View/Helper/DocBlockHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
use Cake\ORM\Association\HasMany;
use Cake\ORM\Association\HasOne;
use Cake\TestSuite\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;

/**
* DocBlockHelper Test
*
* @coversDefaultClass \Bake\View\Helper\DocBlockHelper
*/
#[CoversClass(DocBlockHelper::class)]
class DocBlockHelperTest extends TestCase
{
/**
Expand Down Expand Up @@ -74,7 +74,6 @@ public function tearDown(): void
* Tests the classDescription method including annotation spacing
*
* @return void
* @covers ::classDescription
*/
public function testClassDescription()
{
Expand All @@ -94,7 +93,6 @@ public function testClassDescription()
* Tests the associatedEntityTypeToHintType method
*
* @return void
* @covers ::associatedEntityTypeToHintType
*/
public function testAssociatedEntityTypeToHintType()
{
Expand Down Expand Up @@ -198,8 +196,6 @@ public function testBuildEntityPropertyHintTypeMap()
* Tests the buildEntityAssociationHintTypeMap method
*
* @return void
* @covers ::buildEntityAssociationHintTypeMap
* @covers ::_insertAfter
*/
public function testBuildEntityAssociationHintTypeMap()
{
Expand All @@ -210,7 +206,6 @@ public function testBuildEntityAssociationHintTypeMap()
* Tests the columnTypeToHintType method
*
* @return void
* @covers ::columnTypeToHintType
*/
public function testColumnTypeToHintType()
{
Expand All @@ -221,7 +216,6 @@ public function testColumnTypeToHintType()
* Tests the propertyHints method
*
* @return void
* @covers ::propertyHints
*/
public function testPropertyHints()
{
Expand All @@ -232,7 +226,6 @@ public function testPropertyHints()
* Tests the buildTableAnnotations method
*
* @return void
* @covers ::buildTableAnnotations
*/
public function testBuildTableAnnotations()
{
Expand Down
9 changes: 2 additions & 7 deletions tests/test_app/App/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ public function index()
*/
public function view($id = null)
{
$user = $this->Users->get($id, [
'contain' => [],
]);

$user = $this->Users->get($id, contain: []);
$this->set(compact('user'));
}

Expand Down Expand Up @@ -67,9 +64,7 @@ public function add()
*/
public function edit($id = null)
{
$user = $this->Users->get($id, [
'contain' => [],
]);
$user = $this->Users->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$user = $this->Users->patchEntity($user, $this->request->getData());
if ($this->Users->save($user)) {
Expand Down

0 comments on commit ac26976

Please sign in to comment.