Skip to content

Commit

Permalink
Cover cases with RepositoryInterface
Browse files Browse the repository at this point in the history
Add some test stubs to be used.
  • Loading branch information
ravage84 committed Apr 26, 2024
1 parent 3a21e9f commit 0b60231
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/TestCase/Command/TestCommandTest.php
Expand Up @@ -18,6 +18,8 @@

use Bake\Command\TestCommand;
use Bake\Test\App\Controller\PostsController;
use Bake\Test\App\Model\NonTable\NonTableWithAssociations;
use Bake\Test\App\Model\NonTable\NonTableWithoutAssociations;
use Bake\Test\App\Model\Table\ArticlesTable;
use Bake\Test\App\Model\Table\CategoryThreadsTable;
use Bake\Test\TestCase\TestCase;
Expand Down Expand Up @@ -233,6 +235,39 @@ public function testFixtureArrayGenerationFromModel()
$this->assertEquals($expected, $result);
}

/**
* Test that the generation of fixtures works correctly with a non-table model without associations.
*
* @return void
*/
public function testFixtureArrayGenerationFromNonTableModelWithoutAssociations()
{
$command = new TestCommand();
$subject = new NonTableWithoutAssociations();
$result = $command->generateFixtureList($subject);
$expected = [
'app.NonTableWithoutAssociations',
];
$this->assertEquals($expected, $result);
}

/**
* Test that the generation of fixtures works correctly with a non-table model with associations.
*
* @return void
*/
public function testFixtureArrayGenerationFromNonTableModelWithAssociations()
{
$command = new TestCommand();
$subject = new NonTableWithAssociations();
$result = $command->generateFixtureList($subject);
$expected = [
'app.NonTableWithAssociations',
'app.Users',
];
$this->assertEquals($expected, $result);
}

/**
* test that the generation of fixtures works correctly.
*
Expand Down
86 changes: 86 additions & 0 deletions tests/test_app/App/Model/NonTable/AbstractNonTable.php
@@ -0,0 +1,86 @@
<?php
declare(strict_types=1);

namespace Bake\Test\App\Model\NonTable;

use Cake\Datasource\EntityInterface;
use Cake\Datasource\RepositoryInterface;

/**
* An abstract non-table model with stubbed methods demanded by RepositoryInterface
*/
abstract class AbstractNonTable implements RepositoryInterface
{
public function setAlias(string $alias)
{
}

public function getAlias(): string
{
return substr(static::class, strrpos(static::class, '\\') + 1);
}

public function setRegistryAlias(string $registryAlias)
{
}

public function getRegistryAlias(): string
{
}

public function hasField(string $field): bool
{
}

public function find(string $type = 'all', array $options = [])
{
}

public function get($primaryKey, array $options = []): EntityInterface
{
}

public function query()
{
}

public function updateAll($fields, $conditions): int
{
}

public function deleteAll($conditions): int
{
}

public function exists($conditions): bool
{
}

public function save(EntityInterface $entity, $options = [])
{
}

public function delete(EntityInterface $entity, $options = []): bool
{
}

public function newEmptyEntity(): EntityInterface
{
}

public function newEntity(array $data, array $options = []): EntityInterface
{
}

public function newEntities(array $data, array $options = []): array
{
}

public function patchEntity(EntityInterface $entity, array $data, array $options = []): EntityInterface
{
}

public function patchEntities(iterable $entities, array $data, array $options = []): array
{
}
}
41 changes: 41 additions & 0 deletions tests/test_app/App/Model/NonTable/NonTableWithAssociations.php
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);

namespace Bake\Test\App\Model\NonTable;

use Cake\ORM\Association;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\AssociationCollection;

/**
* A non-table based model with associations
*/
class NonTableWithAssociations extends AbstractNonTable
{
protected $associations;

/**
* Get the associations collection for this table.
*
* @return \Cake\ORM\AssociationCollection The collection of association objects.
*/
public function associations(): AssociationCollection
{
$this->associations = new AssociationCollection();

$this->associations->load(BelongsTo::class, 'Users');

return $this->associations;
}

/**
* Returns an association object configured for the specified alias.
*
* @param string $name The alias used for the association.
* @return \Cake\ORM\Association The association.
*/
public function getAssociation(string $name): Association
{
return $this->associations->get($name);
}
}
11 changes: 11 additions & 0 deletions tests/test_app/App/Model/NonTable/NonTableWithoutAssociations.php
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace Bake\Test\App\Model\NonTable;

/**
* A non-table based model without associations
*/
class NonTableWithoutAssociations extends AbstractNonTable
{
}

0 comments on commit 0b60231

Please sign in to comment.