Initial testing code. Must prove Datetime works.
This commit is contained in:
parent
63a4cb0126
commit
fac2622732
36 changed files with 3989 additions and 24 deletions
.benzine.yml.php_csMakefile
bin
composer.jsondocker-compose.ymlphinx.phpphpunit.xml.distsrc
test
Migrations
app
src
App.php
Models
Services
TableGateways
tests
Models/Generated
Services/Generated
22
.benzine.yml
Normal file
22
.benzine.yml
Normal file
|
@ -0,0 +1,22 @@
|
|||
application:
|
||||
name: Test
|
||||
core: Benzine\ORM\Tests\App
|
||||
default_access: public
|
||||
debug: true
|
||||
root: /app/test/app
|
||||
laminator:
|
||||
templates:
|
||||
- Models
|
||||
- Services
|
||||
#- Controllers
|
||||
#- Endpoints
|
||||
#- Routes
|
||||
databases:
|
||||
default:
|
||||
type: mysql
|
||||
host: $MYSQL_HOST
|
||||
username: $MYSQL_USER
|
||||
password: $MYSQL_PASSWORD
|
||||
database: $MYSQL_DATABASE
|
||||
charset: utf8mb4
|
||||
|
5
.php_cs
5
.php_cs
|
@ -6,9 +6,10 @@ if (!defined('__PHPCS_ROOT__')) {
|
|||
}
|
||||
|
||||
$directories = [
|
||||
__PHPCS_ROOT__.'/src',
|
||||
__PHPCS_ROOT__.'/bin',
|
||||
__PHPCS_ROOT__.'/tests',
|
||||
__PHPCS_ROOT__.'/src',
|
||||
__PHPCS_ROOT__.'/test/src',
|
||||
__PHPCS_ROOT__.'/test/tests',
|
||||
];
|
||||
|
||||
if (isset($additionalDirectories)) {
|
||||
|
|
24
Makefile
24
Makefile
|
@ -1,8 +1,24 @@
|
|||
test-blog-app:
|
||||
SHELL:=/bin/bash
|
||||
UID:=$(shell id -u)
|
||||
DC_RUN:=docker-compose run -u ${UID} --rm
|
||||
|
||||
clear:
|
||||
clear;
|
||||
CURRENT_UID=`id -u`:`id -g` docker-compose run blog-app ./src/Generator/Laminator --workdir=./examples/blog-app
|
||||
|
||||
setup:
|
||||
composer install
|
||||
docker-compose down -v
|
||||
${DC_RUN} test composer install
|
||||
${DC_RUN} test sleep 15
|
||||
|
||||
test: setup test-blog-app
|
||||
migrate:
|
||||
${DC_RUN} test vendor/bin/phinx rollback
|
||||
${DC_RUN} test vendor/bin/phinx migrate
|
||||
|
||||
regen:
|
||||
${DC_RUN} test bin/laminator
|
||||
|
||||
clean:
|
||||
${DC_RUN} test vendor/bin/php-cs-fixer fix
|
||||
|
||||
test: clear setup migrate regen clean
|
||||
${DC_RUN} test vendor/bin/phpunit
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
function detectAndLoadVendor($path = __DIR__)
|
||||
function detectAndLoadVendor($path = __DIR__): void
|
||||
{
|
||||
$path = realpath($path);
|
||||
if ('/' == $path) {
|
||||
|
@ -9,8 +9,8 @@ function detectAndLoadVendor($path = __DIR__)
|
|||
|
||||
foreach (new DirectoryIterator($path) as $fileInfo) {
|
||||
if ($fileInfo->isDir() && 'vendor' == $fileInfo->getFilename()) {
|
||||
define("VENDOR_PATH", $fileInfo->getRealPath());
|
||||
require_once VENDOR_PATH . '/autoload.php';
|
||||
define('VENDOR_PATH', $fileInfo->getRealPath());
|
||||
require_once VENDOR_PATH.'/autoload.php';
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -11,4 +11,4 @@ App::Instance()
|
|||
->getApp()
|
||||
->getContainer()
|
||||
->get(Laminator::class)
|
||||
->makeLaminator(false);
|
||||
->makeLaminator();
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
],
|
||||
"require": {
|
||||
"php": ">=7.4",
|
||||
"ext-simplexml": "*",
|
||||
"laminas/laminas-db": "^2.11.1",
|
||||
"robmorgan/phinx": "^0.12.1",
|
||||
"mattketmo/camel": "^1.1",
|
||||
|
@ -19,10 +20,16 @@
|
|||
"gone.io/twig-extension-inflection": "^1.0",
|
||||
"gone.io/uuid": "^2.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"benzine/core": "dev-master",
|
||||
"phpstan/phpstan": "^0.12",
|
||||
"phpunit/phpcov": "^7.0",
|
||||
"phpunit/phpunit": "^9.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Benzine\\ORM\\": "src",
|
||||
"Benzine\\ORM\\Tests\\": "tests/"
|
||||
"Benzine\\ORM\\Tests\\": "test/app/src"
|
||||
}
|
||||
},
|
||||
"bin": [
|
||||
|
|
|
@ -1,23 +1,30 @@
|
|||
version: "2.3"
|
||||
|
||||
services:
|
||||
blog-app:
|
||||
image: gone/php:nginx
|
||||
test:
|
||||
image: gone/php:cli-7.4
|
||||
volumes:
|
||||
- ./:/app
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
user: ${CURRENT_UID}
|
||||
redis:
|
||||
condition: service_started
|
||||
environment:
|
||||
MYSQL_HOST: mysql
|
||||
MYSQL_USER: testuser
|
||||
MYSQL_PASSWORD: m4&ChangeMe^eN
|
||||
MYSQL_DATABASE: blog
|
||||
|
||||
redis:
|
||||
image: redis
|
||||
|
||||
mysql:
|
||||
image: benzine/mariadb:10.4
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: ChangeMe
|
||||
MYSQL_USER: bloguser
|
||||
MYSQL_USER: testuser
|
||||
MYSQL_PASSWORD: m4&ChangeMe^eN
|
||||
MYSQL_DATABASE: blog
|
||||
ports:
|
||||
- 127.0.0.1:3306:3306
|
||||
volumes:
|
||||
- ./examples/blog-app/blog.sql:/docker-entrypoint-initdb.d/blog.sql
|
||||
- 127.0.0.1:3306:3306
|
30
phinx.php
Normal file
30
phinx.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
require_once(__DIR__ . "/vendor/autoload.php");
|
||||
|
||||
$environment = array_merge($_SERVER, $_ENV);
|
||||
|
||||
$phinxConf =
|
||||
[
|
||||
'paths' => [
|
||||
'migrations' => '%%PHINX_CONFIG_DIR%%/test/Migrations',
|
||||
'seeds' => '%%PHINX_CONFIG_DIR%%/test/Seeds'
|
||||
],
|
||||
'environments' => [
|
||||
'default_environment' => 'testing',
|
||||
'default_migration_table' => 'Migrations',
|
||||
|
||||
'testing' => [
|
||||
'adapter' => 'mysql',
|
||||
'host' => $environment['MYSQL_HOST'],
|
||||
'name' => $environment['MYSQL_DATABASE'],
|
||||
'user' => $environment['MYSQL_USER'],
|
||||
'pass' => $environment['MYSQL_PASSWORD'],
|
||||
'port' => '3306',
|
||||
'charset' => 'utf8',
|
||||
]
|
||||
],
|
||||
'version_order' => 'creation'
|
||||
];
|
||||
|
||||
\Kint::dump($phinxConf);
|
||||
return $phinxConf;
|
57
phpunit.xml.dist
Normal file
57
phpunit.xml.dist
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.0/phpunit.xsd"
|
||||
bootstrap="vendor/autoload.php"
|
||||
backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
forceCoversAnnotation="true"
|
||||
beStrictAboutCoversAnnotation="true"
|
||||
beStrictAboutOutputDuringTests="false"
|
||||
beStrictAboutTodoAnnotatedTests="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
verbose="true"
|
||||
colors="true"
|
||||
cacheResult="true"
|
||||
processIsolation="false"
|
||||
>
|
||||
|
||||
<php>
|
||||
<ini name="memory_limit" value="4096M" />
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Models">
|
||||
<directory>test/app/tests/Models</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Services">
|
||||
<directory>test/app/tests/Services</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<!--<logging>
|
||||
<log type="coverage-html" target=".coverage/phpunit-report"/>
|
||||
<log type="coverage-clover" target=".coverage/phpunit-clover.xml"/>
|
||||
<log type="junit" target=".coverage/phpunit-junit.xml"/>
|
||||
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
|
||||
</logging>-->
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">./src</directory>
|
||||
<exclude>
|
||||
<directory>./vendor</directory>
|
||||
<directory>./views</directory>
|
||||
<directory>./assets</directory>
|
||||
<directory>./bin</directory>
|
||||
<directory>./tests</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
|
||||
<listeners>
|
||||
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
|
||||
</listeners>
|
||||
|
||||
</phpunit>
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Benzine\ORM;
|
||||
|
||||
use Benzine\App;
|
||||
use Benzine\Configuration\Configuration;
|
||||
use Benzine\Configuration\Exceptions\Exception;
|
||||
use Benzine\Exceptions\BenzineException;
|
||||
|
@ -17,9 +18,11 @@ use DirectoryIterator;
|
|||
use Gone\Twig\InflectionExtension;
|
||||
use Gone\Twig\TransformExtension;
|
||||
use Laminas\Stdlib\ConsoleHelper;
|
||||
use Twig\Environment as TwigEnvironment;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Error\RuntimeError;
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Loader\FilesystemLoader as TwigFileSystemLoader;
|
||||
|
||||
class Laminator
|
||||
{
|
||||
|
@ -39,8 +42,8 @@ class Laminator
|
|||
'clean' => [],
|
||||
];
|
||||
private static bool $useClassPrefixes = false;
|
||||
private \Twig\Loader\FilesystemLoader $loader;
|
||||
private \Twig\Environment $twig;
|
||||
private TwigFileSystemLoader $loader;
|
||||
private TwigEnvironment $twig;
|
||||
private Databases $databases;
|
||||
private array $ignoredTables = [];
|
||||
private \SimpleXMLElement $coverageReport;
|
||||
|
@ -82,6 +85,10 @@ class Laminator
|
|||
}
|
||||
}
|
||||
|
||||
if (self::$benzineConfig->has(ConfigurationService::KEY_APP_ROOT)) {
|
||||
$this->setWorkPath(self::$benzineConfig->get(ConfigurationService::KEY_APP_ROOT));
|
||||
}
|
||||
|
||||
$this->loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/Generator/templates');
|
||||
$this->twig = new \Twig\Environment($this->loader, ['debug' => true]);
|
||||
$this->twig->addExtension(new \Twig\Extension\DebugExtension());
|
||||
|
@ -126,6 +133,13 @@ class Laminator
|
|||
return $this->workPath;
|
||||
}
|
||||
|
||||
public function setWorkPath(string $workPath): self
|
||||
{
|
||||
$this->workPath = $workPath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function exceptionHandler($exception): void
|
||||
{
|
||||
// UHOH exception handler
|
||||
|
@ -153,11 +167,9 @@ class Laminator
|
|||
/**
|
||||
* @return \Slim\App
|
||||
*/
|
||||
public function getApp()
|
||||
public function _CORE()
|
||||
{
|
||||
$instanceClass = APP_CORE_NAME;
|
||||
|
||||
return $instanceClass::Instance()
|
||||
return App::Instance()
|
||||
->loadAllRoutes()
|
||||
->getApp()
|
||||
;
|
||||
|
|
53
test/Migrations/20200821163200_test_table_structure.php
Normal file
53
test/Migrations/20200821163200_test_table_structure.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
use Benzine\ORM\Migrations\Migration;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
class TestTableStructure extends Migration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* addCustomColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Any other destructive changes will result in an error when trying to
|
||||
* rollback the migration.
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('Users', ['id' => 'userId'])
|
||||
->addColumn('name', 'string', ['length' => 32])
|
||||
->addIndex(['name'], ['unique' => true])
|
||||
->addColumn('email', 'string', ['length' => 320])
|
||||
->addColumn('created', 'timestamp')
|
||||
->create()
|
||||
;
|
||||
|
||||
$this->table('BlogPosts', ['id' => 'blogPostId'])
|
||||
->addColumn('title', 'string', ['length' => 64])
|
||||
->addIndex(['title'], ['unique' => true])
|
||||
->addColumn('description', 'text')
|
||||
->addColumn('userId', 'integer')
|
||||
->addForeignKey('userId', 'Users', 'userId')
|
||||
->addColumn('created', 'timestamp')
|
||||
->create()
|
||||
;
|
||||
}
|
||||
}
|
7
test/app/src/App.php
Normal file
7
test/app/src/App.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
namespace Benzine\ORM\Tests;
|
||||
|
||||
class App extends \Benzine\App
|
||||
{
|
||||
|
||||
}
|
315
test/app/src/Models/Base/BaseBlogPostsModel.php
Executable file
315
test/app/src/Models/Base/BaseBlogPostsModel.php
Executable file
|
@ -0,0 +1,315 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\Models\Base;
|
||||
|
||||
use Benzine\ORM\Tests\Models;
|
||||
use Benzine\ORM\Tests\TableGateways;
|
||||
use Benzine\ORM\Tests\Services;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Benzine\ORM\Abstracts\Model as AbstractModel;
|
||||
use Benzine\ORM\Interfaces\ModelInterface as ModelInterface;
|
||||
use Benzine\App as App;
|
||||
|
||||
/** ___ __
|
||||
* / _ \___ ____ ___ ____ ____/ /
|
||||
* / // / _ `/ _ \/ _ `/ -_) __/_/
|
||||
* /____/\_,_/_//_/\_, /\__/_/ (_)
|
||||
* /___/.
|
||||
*
|
||||
* Anything in this file is prone to being overwritten!
|
||||
*
|
||||
* This file was programmatically generated. To modify
|
||||
* this classes behaviours, do so in the class that
|
||||
* extends this, or modify the Laminator Template!
|
||||
*/
|
||||
abstract class BaseBlogPostsModel extends AbstractModel implements ModelInterface
|
||||
{
|
||||
// Declare what fields are available on this object
|
||||
public const FIELD_BLOGPOSTID = 'blogPostId';
|
||||
public const FIELD_TITLE = 'title';
|
||||
public const FIELD_DESCRIPTION = 'description';
|
||||
public const FIELD_USERID = 'userId';
|
||||
public const FIELD_CREATED = 'created';
|
||||
|
||||
public const TYPE_BLOGPOSTID = 'int';
|
||||
public const TYPE_TITLE = 'varchar';
|
||||
public const TYPE_DESCRIPTION = 'text';
|
||||
public const TYPE_USERID = 'int';
|
||||
public const TYPE_CREATED = 'timestamp';
|
||||
|
||||
// Constant arrays defined by ENUMs
|
||||
|
||||
// Constants defined by ENUMs
|
||||
|
||||
protected array $_primary_keys = [
|
||||
'blogPostId' => 'blogPostId',
|
||||
];
|
||||
|
||||
protected array $_autoincrement_keys = [
|
||||
'blogPostId' => 'blogPostId',
|
||||
];
|
||||
|
||||
// PHPType: int. DBType: int. Max Length: 2147483647.
|
||||
protected ?int $blogPostId = null;
|
||||
|
||||
// PHPType: string. DBType: varchar. Max Length: .
|
||||
protected ?string $title = null;
|
||||
|
||||
// PHPType: string. DBType: text. Max Length: .
|
||||
protected ?string $description = null;
|
||||
|
||||
// PHPType: int. DBType: int. Max Length: 2147483647.
|
||||
protected ?int $userId = null;
|
||||
|
||||
// PHPType: string. DBType: timestamp. Max Length: .
|
||||
protected ?string $created = null;
|
||||
|
||||
|
||||
private Services\UsersService $usersService;
|
||||
|
||||
/** Caching entities **/
|
||||
protected array $cache = [];
|
||||
protected ?Models\UsersModel $cachedUserObject;
|
||||
|
||||
/**
|
||||
* Lazy loading function to get an instance of Services\BlogPostsService
|
||||
*
|
||||
* @return Services\UsersService
|
||||
*/
|
||||
protected function getUsersService() : Services\UsersService
|
||||
{
|
||||
if (!isset($this->usersService)){
|
||||
$this->usersService = App::DI(Services\UsersService::class);
|
||||
}
|
||||
|
||||
return $this->usersService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data an array of a Models\BlogPostsModel's properties
|
||||
*
|
||||
* @return Models\BlogPostsModel
|
||||
*/
|
||||
public static function factory(array $data = [])
|
||||
{
|
||||
return parent::factory($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array describing the properties of this model.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPropertyMeta(): array
|
||||
{
|
||||
$usersService = App::DI(Services\BlogPostsService::class);
|
||||
return [
|
||||
self::FIELD_BLOGPOSTID => [
|
||||
'type' => self::TYPE_BLOGPOSTID,
|
||||
],
|
||||
self::FIELD_TITLE => [
|
||||
'type' => self::TYPE_TITLE,
|
||||
'length' => 64,
|
||||
],
|
||||
self::FIELD_DESCRIPTION => [
|
||||
'type' => self::TYPE_DESCRIPTION,
|
||||
'length' => 65535,
|
||||
],
|
||||
self::FIELD_USERID => [
|
||||
'type' => self::TYPE_USERID,
|
||||
'remoteOptionsLoader' => $usersService->getAll(),
|
||||
],
|
||||
self::FIELD_CREATED => [
|
||||
'type' => self::TYPE_CREATED,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function getBlogPostId(): ?int
|
||||
{
|
||||
return $this->blogPostId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $blogPostId
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setBlogPostId(int $blogPostId = null): self
|
||||
{
|
||||
$this->blogPostId = $blogPostId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setTitle(string $title = null): self
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setDescription(string $description = null): self
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUserId(): ?int
|
||||
{
|
||||
return $this->userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setUserId(int $userId = null): self
|
||||
{
|
||||
$this->userId = $userId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreated(): ?string
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $created
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setCreated(string $created = null): self
|
||||
{
|
||||
$this->created = $created;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function fetchUserObject(): ?Models\UsersModel
|
||||
{
|
||||
if (!isset($this->cachedUserObject)){
|
||||
$this->cachedUserObject = $this->getUsersService()
|
||||
->getByField('userId', $this->getUserId());
|
||||
}
|
||||
return $this->cachedUserObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function save(): Models\BlogPostsModel
|
||||
{
|
||||
/** @var TableGateways\BlogPostsTableGateway $tableGateway */
|
||||
$tableGateway = App::DI(TableGateways\BlogPostsTableGateway::class);
|
||||
|
||||
return $tableGateway->save($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the current record.
|
||||
* Returns the number of affected rows.
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function destroy(): int
|
||||
{
|
||||
/** @var TableGateways\BlogPostsTableGateway $tableGateway */
|
||||
$tableGateway = App::DI(TableGateways\BlogPostsTableGateway::class);
|
||||
|
||||
return $tableGateway->delete($this->getPrimaryKeys_dbColumns());
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the current record, and any dependencies upon it, recursively.
|
||||
* Returns the number of affected rows.
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function destroyThoroughly(): int
|
||||
{
|
||||
return $this->destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides an array of all properties in this model.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getListOfProperties(): array
|
||||
{
|
||||
return [
|
||||
'blogPostId' => 'blogPostId',
|
||||
'title' => 'title',
|
||||
'description' => 'description',
|
||||
'userId' => 'userId',
|
||||
'created' => 'created',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Take an input array $data, and turn that array into a hydrated object.
|
||||
*
|
||||
* This has been re-written to be as permissive as possible with loading in data. This at some point will need to
|
||||
* be re-re-written as a less messy solution (ie: picking one input field style and sticking with it)
|
||||
*
|
||||
* @todo re-rewrite this: pick one input field style and stick with it
|
||||
*
|
||||
* @param array $data dehydated object array
|
||||
*
|
||||
* @return Models\BlogPostsModel
|
||||
*/
|
||||
public function exchangeArray(array $data): self
|
||||
{
|
||||
if (isset($data['blogPostId'])) $this->setBlogPostId($data['blogPostId']);
|
||||
if (isset($data['blogPostId'])) $this->setBlogPostId($data['blogPostId']);
|
||||
if (isset($data['BlogPostId'])) $this->setBlogPostId($data['BlogPostId']);
|
||||
if (isset($data['title'])) $this->setTitle($data['title']);
|
||||
if (isset($data['title'])) $this->setTitle($data['title']);
|
||||
if (isset($data['Title'])) $this->setTitle($data['Title']);
|
||||
if (isset($data['description'])) $this->setDescription($data['description']);
|
||||
if (isset($data['description'])) $this->setDescription($data['description']);
|
||||
if (isset($data['Description'])) $this->setDescription($data['Description']);
|
||||
if (isset($data['userId'])) $this->setUserId($data['userId']);
|
||||
if (isset($data['userId'])) $this->setUserId($data['userId']);
|
||||
if (isset($data['UserId'])) $this->setUserId($data['UserId']);
|
||||
if (isset($data['created'])) $this->setCreated($data['created']);
|
||||
if (isset($data['created'])) $this->setCreated($data['created']);
|
||||
if (isset($data['Created'])) $this->setCreated($data['Created']);
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
280
test/app/src/Models/Base/BaseMigrationsModel.php
Executable file
280
test/app/src/Models/Base/BaseMigrationsModel.php
Executable file
|
@ -0,0 +1,280 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\Models\Base;
|
||||
|
||||
use Benzine\ORM\Tests\Models;
|
||||
use Benzine\ORM\Tests\TableGateways;
|
||||
use Benzine\ORM\Tests\Services;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Benzine\ORM\Abstracts\Model as AbstractModel;
|
||||
use Benzine\ORM\Interfaces\ModelInterface as ModelInterface;
|
||||
use Benzine\App as App;
|
||||
|
||||
/** ___ __
|
||||
* / _ \___ ____ ___ ____ ____/ /
|
||||
* / // / _ `/ _ \/ _ `/ -_) __/_/
|
||||
* /____/\_,_/_//_/\_, /\__/_/ (_)
|
||||
* /___/.
|
||||
*
|
||||
* Anything in this file is prone to being overwritten!
|
||||
*
|
||||
* This file was programmatically generated. To modify
|
||||
* this classes behaviours, do so in the class that
|
||||
* extends this, or modify the Laminator Template!
|
||||
*/
|
||||
abstract class BaseMigrationsModel extends AbstractModel implements ModelInterface
|
||||
{
|
||||
// Declare what fields are available on this object
|
||||
public const FIELD_VERSION = 'version';
|
||||
public const FIELD_MIGRATION_NAME = 'migration_name';
|
||||
public const FIELD_START_TIME = 'start_time';
|
||||
public const FIELD_END_TIME = 'end_time';
|
||||
public const FIELD_BREAKPOINT = 'breakpoint';
|
||||
|
||||
public const TYPE_VERSION = 'bigint';
|
||||
public const TYPE_MIGRATION_NAME = 'varchar';
|
||||
public const TYPE_START_TIME = 'timestamp';
|
||||
public const TYPE_END_TIME = 'timestamp';
|
||||
public const TYPE_BREAKPOINT = 'tinyint';
|
||||
|
||||
// Constant arrays defined by ENUMs
|
||||
|
||||
// Constants defined by ENUMs
|
||||
|
||||
protected array $_primary_keys = [
|
||||
'version' => 'version',
|
||||
];
|
||||
|
||||
// PHPType: int. DBType: bigint. Max Length: 9223372036854775807.
|
||||
protected ?int $version = null;
|
||||
|
||||
// PHPType: string. DBType: varchar. Max Length: .
|
||||
protected ?string $migration_name = null;
|
||||
|
||||
// PHPType: string. DBType: timestamp. Max Length: .
|
||||
protected ?string $start_time = null;
|
||||
|
||||
// PHPType: string. DBType: timestamp. Max Length: .
|
||||
protected ?string $end_time = null;
|
||||
|
||||
// PHPType: int. DBType: tinyint. Max Length: 127.
|
||||
protected ?int $breakpoint = null;
|
||||
|
||||
|
||||
|
||||
/** Caching entities **/
|
||||
protected array $cache = [];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data an array of a Models\MigrationsModel's properties
|
||||
*
|
||||
* @return Models\MigrationsModel
|
||||
*/
|
||||
public static function factory(array $data = [])
|
||||
{
|
||||
return parent::factory($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array describing the properties of this model.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPropertyMeta(): array
|
||||
{
|
||||
return [
|
||||
self::FIELD_VERSION => [
|
||||
'type' => self::TYPE_VERSION,
|
||||
],
|
||||
self::FIELD_MIGRATION_NAME => [
|
||||
'type' => self::TYPE_MIGRATION_NAME,
|
||||
'length' => 100,
|
||||
],
|
||||
self::FIELD_START_TIME => [
|
||||
'type' => self::TYPE_START_TIME,
|
||||
],
|
||||
self::FIELD_END_TIME => [
|
||||
'type' => self::TYPE_END_TIME,
|
||||
],
|
||||
self::FIELD_BREAKPOINT => [
|
||||
'type' => self::TYPE_BREAKPOINT,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function getVersion(): ?int
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $version
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setVersion(int $version = null): self
|
||||
{
|
||||
$this->version = $version;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMigration_name(): ?string
|
||||
{
|
||||
return $this->migration_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $migration_name
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setMigration_name(string $migration_name = null): self
|
||||
{
|
||||
$this->migration_name = $migration_name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStart_time(): ?string
|
||||
{
|
||||
return $this->start_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $start_time
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setStart_time(string $start_time = null): self
|
||||
{
|
||||
$this->start_time = $start_time;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEnd_time(): ?string
|
||||
{
|
||||
return $this->end_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $end_time
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setEnd_time(string $end_time = null): self
|
||||
{
|
||||
$this->end_time = $end_time;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBreakpoint(): ?int
|
||||
{
|
||||
return $this->breakpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $breakpoint
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setBreakpoint(int $breakpoint = null): self
|
||||
{
|
||||
$this->breakpoint = $breakpoint;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function save(): Models\MigrationsModel
|
||||
{
|
||||
/** @var TableGateways\MigrationsTableGateway $tableGateway */
|
||||
$tableGateway = App::DI(TableGateways\MigrationsTableGateway::class);
|
||||
|
||||
return $tableGateway->save($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the current record.
|
||||
* Returns the number of affected rows.
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function destroy(): int
|
||||
{
|
||||
/** @var TableGateways\MigrationsTableGateway $tableGateway */
|
||||
$tableGateway = App::DI(TableGateways\MigrationsTableGateway::class);
|
||||
|
||||
return $tableGateway->delete($this->getPrimaryKeys_dbColumns());
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the current record, and any dependencies upon it, recursively.
|
||||
* Returns the number of affected rows.
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function destroyThoroughly(): int
|
||||
{
|
||||
return $this->destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides an array of all properties in this model.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getListOfProperties(): array
|
||||
{
|
||||
return [
|
||||
'version' => 'version',
|
||||
'migration_name' => 'migration_name',
|
||||
'start_time' => 'start_time',
|
||||
'end_time' => 'end_time',
|
||||
'breakpoint' => 'breakpoint',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Take an input array $data, and turn that array into a hydrated object.
|
||||
*
|
||||
* This has been re-written to be as permissive as possible with loading in data. This at some point will need to
|
||||
* be re-re-written as a less messy solution (ie: picking one input field style and sticking with it)
|
||||
*
|
||||
* @todo re-rewrite this: pick one input field style and stick with it
|
||||
*
|
||||
* @param array $data dehydated object array
|
||||
*
|
||||
* @return Models\MigrationsModel
|
||||
*/
|
||||
public function exchangeArray(array $data): self
|
||||
{
|
||||
if (isset($data['version'])) $this->setVersion($data['version']);
|
||||
if (isset($data['version'])) $this->setVersion($data['version']);
|
||||
if (isset($data['Version'])) $this->setVersion($data['Version']);
|
||||
if (isset($data['migration_name'])) $this->setMigration_name($data['migration_name']);
|
||||
if (isset($data['migration_name'])) $this->setMigration_name($data['migration_name']);
|
||||
if (isset($data['Migration_name'])) $this->setMigration_name($data['Migration_name']);
|
||||
if (isset($data['start_time'])) $this->setStart_time($data['start_time']);
|
||||
if (isset($data['start_time'])) $this->setStart_time($data['start_time']);
|
||||
if (isset($data['Start_time'])) $this->setStart_time($data['Start_time']);
|
||||
if (isset($data['end_time'])) $this->setEnd_time($data['end_time']);
|
||||
if (isset($data['end_time'])) $this->setEnd_time($data['end_time']);
|
||||
if (isset($data['End_time'])) $this->setEnd_time($data['End_time']);
|
||||
if (isset($data['breakpoint'])) $this->setBreakpoint($data['breakpoint']);
|
||||
if (isset($data['breakpoint'])) $this->setBreakpoint($data['breakpoint']);
|
||||
if (isset($data['Breakpoint'])) $this->setBreakpoint($data['Breakpoint']);
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
352
test/app/src/Models/Base/BaseUsersModel.php
Executable file
352
test/app/src/Models/Base/BaseUsersModel.php
Executable file
|
@ -0,0 +1,352 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\Models\Base;
|
||||
|
||||
use Benzine\ORM\Tests\Models;
|
||||
use Benzine\ORM\Tests\TableGateways;
|
||||
use Benzine\ORM\Tests\Services;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Benzine\ORM\Abstracts\Model as AbstractModel;
|
||||
use Benzine\ORM\Interfaces\ModelInterface as ModelInterface;
|
||||
use Benzine\App as App;
|
||||
|
||||
/** ___ __
|
||||
* / _ \___ ____ ___ ____ ____/ /
|
||||
* / // / _ `/ _ \/ _ `/ -_) __/_/
|
||||
* /____/\_,_/_//_/\_, /\__/_/ (_)
|
||||
* /___/.
|
||||
*
|
||||
* Anything in this file is prone to being overwritten!
|
||||
*
|
||||
* This file was programmatically generated. To modify
|
||||
* this classes behaviours, do so in the class that
|
||||
* extends this, or modify the Laminator Template!
|
||||
*/
|
||||
abstract class BaseUsersModel extends AbstractModel implements ModelInterface
|
||||
{
|
||||
// Declare what fields are available on this object
|
||||
public const FIELD_USERID = 'userId';
|
||||
public const FIELD_NAME = 'name';
|
||||
public const FIELD_EMAIL = 'email';
|
||||
public const FIELD_CREATED = 'created';
|
||||
|
||||
public const TYPE_USERID = 'int';
|
||||
public const TYPE_NAME = 'varchar';
|
||||
public const TYPE_EMAIL = 'varchar';
|
||||
public const TYPE_CREATED = 'timestamp';
|
||||
|
||||
// Constant arrays defined by ENUMs
|
||||
|
||||
// Constants defined by ENUMs
|
||||
|
||||
protected array $_primary_keys = [
|
||||
'userId' => 'userId',
|
||||
];
|
||||
|
||||
protected array $_autoincrement_keys = [
|
||||
'userId' => 'userId',
|
||||
];
|
||||
|
||||
// PHPType: int. DBType: int. Max Length: 2147483647.
|
||||
protected ?int $userId = null;
|
||||
|
||||
// PHPType: string. DBType: varchar. Max Length: .
|
||||
protected ?string $name = null;
|
||||
|
||||
// PHPType: string. DBType: varchar. Max Length: .
|
||||
protected ?string $email = null;
|
||||
|
||||
// PHPType: string. DBType: timestamp. Max Length: .
|
||||
protected ?string $created = null;
|
||||
|
||||
|
||||
private Services\BlogPostsService $blogPostsService;
|
||||
|
||||
/** Caching entities **/
|
||||
protected array $cache = [];
|
||||
protected ?Models\BlogPostsModel $cachedBlogPostObject;
|
||||
|
||||
|
||||
/**
|
||||
* Lazy loading function to get an instance of Services\BlogPostsService
|
||||
*
|
||||
* @return Services\BlogPostsService
|
||||
*/
|
||||
protected function getBlogPostsService() : Services\BlogPostsService
|
||||
{
|
||||
if (!isset($this->blogPostsService)){
|
||||
$this->blogPostsService = App::DI(Services\BlogPostsService::class);
|
||||
}
|
||||
|
||||
return $this->blogPostsService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data an array of a Models\UsersModel's properties
|
||||
*
|
||||
* @return Models\UsersModel
|
||||
*/
|
||||
public static function factory(array $data = [])
|
||||
{
|
||||
return parent::factory($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array describing the properties of this model.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPropertyMeta(): array
|
||||
{
|
||||
return [
|
||||
self::FIELD_USERID => [
|
||||
'type' => self::TYPE_USERID,
|
||||
],
|
||||
self::FIELD_NAME => [
|
||||
'type' => self::TYPE_NAME,
|
||||
'length' => 32,
|
||||
],
|
||||
self::FIELD_EMAIL => [
|
||||
'type' => self::TYPE_EMAIL,
|
||||
'length' => 320,
|
||||
],
|
||||
self::FIELD_CREATED => [
|
||||
'type' => self::TYPE_CREATED,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function getUserId(): ?int
|
||||
{
|
||||
return $this->userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setUserId(int $userId = null): self
|
||||
{
|
||||
$this->userId = $userId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setName(string $name = null): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEmail(): ?string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setEmail(string $email = null): self
|
||||
{
|
||||
$this->email = $email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreated(): ?string
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $created
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setCreated(string $created = null): self
|
||||
{
|
||||
$this->created = $created;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a singular BlogPost that references this Models\UsersModel.
|
||||
*
|
||||
* Local class: BlogPosts
|
||||
* Remote class: Users
|
||||
*
|
||||
* @param $orderBy string Column to order by. Recommended to use the Constants in Models\BlogPostsModel::
|
||||
* @param $orderDirection string Either "DESC" or "ASC". Recommend using Select::ORDER_ASCENDING or Select::ORDER_DESCENDING
|
||||
*
|
||||
* @return Models\BlogPostsModel|null
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function fetchBlogPostObject(
|
||||
$orderBy = null,
|
||||
$orderDirection='ASC'
|
||||
): ?Models\BlogPostsModel {
|
||||
if (!isset($this->cachedBlogPostObject)){
|
||||
$this->cachedBlogPostObject = $this->getBlogPostsService()
|
||||
->getByField(
|
||||
Models\UsersModel::FIELD_USERID,
|
||||
$this->getUserId(),
|
||||
$orderBy,
|
||||
$orderDirection
|
||||
);
|
||||
}
|
||||
return $this->cachedBlogPostObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all matching BlogPost that reference this Models\UsersModel.
|
||||
*
|
||||
* Local class: BlogPosts
|
||||
* Remote class: Users
|
||||
*
|
||||
* @param $limit int Number to fetch maximum
|
||||
* @param $orderBy string Column to order by. Recommended to use the Constants in Models\BlogPostsModel::
|
||||
* @param $orderDirection string Either "DESC" or "ASC". Recommend using Select::ORDER_ASCENDING or Select::ORDER_DESCENDING
|
||||
*
|
||||
* @return Models\BlogPostsModel[]|null
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function fetchBlogPostObjects(
|
||||
int $limit = null,
|
||||
string $orderBy = null,
|
||||
string $orderDirection='ASC'
|
||||
): ?array {
|
||||
if (!isset($this->cachedBlogPostObjects)){
|
||||
$this->cachedBlogPostObjects = $this
|
||||
->getBlogPostsService()
|
||||
->getManyByField(
|
||||
Models\BlogPostsModel::FIELD_USERID,
|
||||
$this->getUserId(),
|
||||
$limit,
|
||||
$orderBy,
|
||||
$orderDirection
|
||||
);
|
||||
}
|
||||
|
||||
return $this->cachedBlogPostObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of matching BlogPost that reference this Models\UsersModel.
|
||||
* Returns the number of objects found.
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function countBlogPostObjects(): int {
|
||||
return $this
|
||||
->getBlogPostsService()
|
||||
->countByField(
|
||||
Models\UsersModel::FIELD_USERID,
|
||||
$this->getUserId()
|
||||
);
|
||||
}
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function save(): Models\UsersModel
|
||||
{
|
||||
/** @var TableGateways\UsersTableGateway $tableGateway */
|
||||
$tableGateway = App::DI(TableGateways\UsersTableGateway::class);
|
||||
|
||||
return $tableGateway->save($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the current record.
|
||||
* Returns the number of affected rows.
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function destroy(): int
|
||||
{
|
||||
/** @var TableGateways\UsersTableGateway $tableGateway */
|
||||
$tableGateway = App::DI(TableGateways\UsersTableGateway::class);
|
||||
|
||||
return $tableGateway->delete($this->getPrimaryKeys_dbColumns());
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the current record, and any dependencies upon it, recursively.
|
||||
* Returns the number of affected rows.
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function destroyThoroughly(): int
|
||||
{
|
||||
return $this->destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides an array of all properties in this model.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getListOfProperties(): array
|
||||
{
|
||||
return [
|
||||
'userId' => 'userId',
|
||||
'name' => 'name',
|
||||
'email' => 'email',
|
||||
'created' => 'created',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Take an input array $data, and turn that array into a hydrated object.
|
||||
*
|
||||
* This has been re-written to be as permissive as possible with loading in data. This at some point will need to
|
||||
* be re-re-written as a less messy solution (ie: picking one input field style and sticking with it)
|
||||
*
|
||||
* @todo re-rewrite this: pick one input field style and stick with it
|
||||
*
|
||||
* @param array $data dehydated object array
|
||||
*
|
||||
* @return Models\UsersModel
|
||||
*/
|
||||
public function exchangeArray(array $data): self
|
||||
{
|
||||
if (isset($data['userId'])) $this->setUserId($data['userId']);
|
||||
if (isset($data['userId'])) $this->setUserId($data['userId']);
|
||||
if (isset($data['UserId'])) $this->setUserId($data['UserId']);
|
||||
if (isset($data['name'])) $this->setName($data['name']);
|
||||
if (isset($data['name'])) $this->setName($data['name']);
|
||||
if (isset($data['Name'])) $this->setName($data['Name']);
|
||||
if (isset($data['email'])) $this->setEmail($data['email']);
|
||||
if (isset($data['email'])) $this->setEmail($data['email']);
|
||||
if (isset($data['Email'])) $this->setEmail($data['Email']);
|
||||
if (isset($data['created'])) $this->setCreated($data['created']);
|
||||
if (isset($data['created'])) $this->setCreated($data['created']);
|
||||
if (isset($data['Created'])) $this->setCreated($data['Created']);
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
7
test/app/src/Models/BlogPostsModel.php
Executable file
7
test/app/src/Models/BlogPostsModel.php
Executable file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
namespace Benzine\ORM\Tests\Models;
|
||||
|
||||
class BlogPostsModel extends Base\BaseBlogPostsModel
|
||||
{
|
||||
|
||||
}
|
7
test/app/src/Models/MigrationsModel.php
Executable file
7
test/app/src/Models/MigrationsModel.php
Executable file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
namespace Benzine\ORM\Tests\Models;
|
||||
|
||||
class MigrationsModel extends Base\BaseMigrationsModel
|
||||
{
|
||||
|
||||
}
|
7
test/app/src/Models/UsersModel.php
Executable file
7
test/app/src/Models/UsersModel.php
Executable file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
namespace Benzine\ORM\Tests\Models;
|
||||
|
||||
class UsersModel extends Base\BaseUsersModel
|
||||
{
|
||||
|
||||
}
|
222
test/app/src/Services/Base/BaseBlogPostsService.php
Executable file
222
test/app/src/Services/Base/BaseBlogPostsService.php
Executable file
|
@ -0,0 +1,222 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\Services\Base;
|
||||
|
||||
use Benzine\ORM\Tests\Models;
|
||||
use Benzine\ORM\Tests\TableGateways;
|
||||
use Laminas\Db\Sql\Expression;
|
||||
use Laminas\Db\Sql\Select;
|
||||
use Laminas\Db\Sql\Predicate;
|
||||
use Laminas\Db\Sql\Where;
|
||||
use Benzine\ORM\Abstracts\Service as AbstractService;
|
||||
use Benzine\ORM\Interfaces\ServiceInterface as ServiceInterface;
|
||||
|
||||
/** ___ __
|
||||
* / _ \___ ____ ___ ____ ____/ /
|
||||
* / // / _ `/ _ \/ _ `/ -_) __/_/
|
||||
* /____/\_,_/_//_/\_, /\__/_/ (_)
|
||||
* /___/.
|
||||
*
|
||||
* Anything in this file is prone to being overwritten!
|
||||
*
|
||||
* This file was programmatically generated. To modify
|
||||
* this classes behaviours, do so in the class that
|
||||
* extends this, or modify the Laminator Template!
|
||||
*/
|
||||
abstract class BaseBlogPostsService extends AbstractService implements ServiceInterface
|
||||
{
|
||||
// Related Objects Table Gateways
|
||||
protected TableGateways\UsersTableGateway $usersTableGateway;
|
||||
|
||||
// Remote Constraints Table Gateways
|
||||
|
||||
// Self Table Gateway
|
||||
protected TableGateways\BlogPostsTableGateway $blogPostsTableGateway;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param TableGateways\UsersTableGateway $usersTableGateway
|
||||
* @param TableGateways\BlogPostsTableGateway $blogPostsTableGateway
|
||||
*/
|
||||
public function __construct(
|
||||
TableGateways\UsersTableGateway $usersTableGateway,
|
||||
TableGateways\BlogPostsTableGateway $blogPostsTableGateway
|
||||
) {
|
||||
$this->usersTableGateway = $usersTableGateway;
|
||||
$this->blogPostsTableGateway = $blogPostsTableGateway;
|
||||
}
|
||||
|
||||
public function getNewTableGatewayInstance(): TableGateways\BlogPostsTableGateway
|
||||
{
|
||||
return $this->blogPostsTableGateway;
|
||||
}
|
||||
|
||||
public function getNewModelInstance($dataExchange = []): Models\BlogPostsModel
|
||||
{
|
||||
return $this->blogPostsTableGateway->getNewModelInstance($dataExchange);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|int $limit
|
||||
* @param null|int $offset
|
||||
* @param null|array|\Closure[] $wheres
|
||||
* @param null|Expression|string $order
|
||||
* @param null|string $orderDirection
|
||||
*
|
||||
* @return Models\BlogPostsModel[]
|
||||
*/
|
||||
public function getAll(
|
||||
int $limit = null,
|
||||
int $offset = null,
|
||||
array $wheres = null,
|
||||
$order = null,
|
||||
string $orderDirection = null
|
||||
) {
|
||||
return parent::getAll(
|
||||
$limit,
|
||||
$offset,
|
||||
$wheres,
|
||||
$order,
|
||||
$orderDirection
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return null|Models\BlogPostsModel
|
||||
*/
|
||||
public function getByField(string $field, $value, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?Models\BlogPostsModel
|
||||
{
|
||||
/** @var TableGateways\BlogPostsTableGateway $blogPostsTable */
|
||||
$blogPostsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $blogPostsTable->getByField($field, $value, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
* @param $limit int
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return null|Models\BlogPostsModel[]
|
||||
*/
|
||||
public function getManyByField(string $field, $value, int $limit = null, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?array
|
||||
{
|
||||
/** @var TableGateways\BlogPostsTableGateway $blogPostsTable */
|
||||
$blogPostsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $blogPostsTable->getManyByField($field, $value, $limit, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countByField(string $field, $value): int
|
||||
{
|
||||
$blogPostsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $blogPostsTable->countByField($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Models\BlogPostsModel
|
||||
*/
|
||||
public function getRandom(): ?Models\BlogPostsModel
|
||||
{
|
||||
/** @var TableGateways\BlogPostsTableGateway $blogPostsTable */
|
||||
$blogPostsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $blogPostsTable->fetchRandom();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|\Closure|Predicate\PredicateInterface|string|Where $keyValue
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return Models\BlogPostsModel
|
||||
*/
|
||||
public function getMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?Models\BlogPostsModel
|
||||
{
|
||||
/** @var TableGateways\BlogPostsTableGateway $blogPostsTable */
|
||||
$blogPostsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $blogPostsTable->getMatching($keyValue, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|\Closure|Predicate\PredicateInterface|string|Where $keyValue
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
* @param $limit int Limit the number of matches returned
|
||||
*
|
||||
* @return Models\BlogPostsModel[]
|
||||
*/
|
||||
public function getManyMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING, int $limit = null): ?array
|
||||
{
|
||||
/** @var TableGateways\BlogPostsTableGateway $blogPostsTable */
|
||||
$blogPostsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $blogPostsTable->getManyMatching($keyValue, $orderBy, $orderDirection, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dataExchange
|
||||
*
|
||||
* @return Models\BlogPostsModel
|
||||
*/
|
||||
public function createFromArray($dataExchange): Models\BlogPostsModel
|
||||
{
|
||||
/** @var TableGateways\BlogPostsTableGateway $blogPostsTable */
|
||||
$blogPostsTable = $this->getNewTableGatewayInstance();
|
||||
$blogPosts = $this->getNewModelInstance($dataExchange);
|
||||
|
||||
return $blogPostsTable->save($blogPosts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function deleteByField(string $field, $value): int
|
||||
{
|
||||
/** @var TableGateways\BlogPostsTableGateway $blogPostsTable */
|
||||
$blogPostsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $blogPostsTable->delete([$field => $value]);
|
||||
}
|
||||
|
||||
public function getTermPlural(): string
|
||||
{
|
||||
return 'BlogPosts';
|
||||
}
|
||||
|
||||
public function getTermSingular(): string
|
||||
{
|
||||
return 'BlogPosts';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a version of this object pre-populated with nonsense.
|
||||
*
|
||||
* @returns Models\BlogPostsModel
|
||||
*/
|
||||
public function getMockObject(): Models\BlogPostsModel
|
||||
{
|
||||
return $this->getNewTableGatewayInstance()->getNewMockModelInstance();
|
||||
}
|
||||
}
|
218
test/app/src/Services/Base/BaseMigrationsService.php
Executable file
218
test/app/src/Services/Base/BaseMigrationsService.php
Executable file
|
@ -0,0 +1,218 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\Services\Base;
|
||||
|
||||
use Benzine\ORM\Tests\Models;
|
||||
use Benzine\ORM\Tests\TableGateways;
|
||||
use Laminas\Db\Sql\Expression;
|
||||
use Laminas\Db\Sql\Select;
|
||||
use Laminas\Db\Sql\Predicate;
|
||||
use Laminas\Db\Sql\Where;
|
||||
use Benzine\ORM\Abstracts\Service as AbstractService;
|
||||
use Benzine\ORM\Interfaces\ServiceInterface as ServiceInterface;
|
||||
|
||||
/** ___ __
|
||||
* / _ \___ ____ ___ ____ ____/ /
|
||||
* / // / _ `/ _ \/ _ `/ -_) __/_/
|
||||
* /____/\_,_/_//_/\_, /\__/_/ (_)
|
||||
* /___/.
|
||||
*
|
||||
* Anything in this file is prone to being overwritten!
|
||||
*
|
||||
* This file was programmatically generated. To modify
|
||||
* this classes behaviours, do so in the class that
|
||||
* extends this, or modify the Laminator Template!
|
||||
*/
|
||||
abstract class BaseMigrationsService extends AbstractService implements ServiceInterface
|
||||
{
|
||||
// Related Objects Table Gateways
|
||||
|
||||
// Remote Constraints Table Gateways
|
||||
|
||||
// Self Table Gateway
|
||||
protected TableGateways\MigrationsTableGateway $migrationsTableGateway;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param TableGateways\MigrationsTableGateway $migrationsTableGateway
|
||||
*/
|
||||
public function __construct(
|
||||
TableGateways\MigrationsTableGateway $migrationsTableGateway
|
||||
) {
|
||||
$this->migrationsTableGateway = $migrationsTableGateway;
|
||||
}
|
||||
|
||||
public function getNewTableGatewayInstance(): TableGateways\MigrationsTableGateway
|
||||
{
|
||||
return $this->migrationsTableGateway;
|
||||
}
|
||||
|
||||
public function getNewModelInstance($dataExchange = []): Models\MigrationsModel
|
||||
{
|
||||
return $this->migrationsTableGateway->getNewModelInstance($dataExchange);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|int $limit
|
||||
* @param null|int $offset
|
||||
* @param null|array|\Closure[] $wheres
|
||||
* @param null|Expression|string $order
|
||||
* @param null|string $orderDirection
|
||||
*
|
||||
* @return Models\MigrationsModel[]
|
||||
*/
|
||||
public function getAll(
|
||||
int $limit = null,
|
||||
int $offset = null,
|
||||
array $wheres = null,
|
||||
$order = null,
|
||||
string $orderDirection = null
|
||||
) {
|
||||
return parent::getAll(
|
||||
$limit,
|
||||
$offset,
|
||||
$wheres,
|
||||
$order,
|
||||
$orderDirection
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return null|Models\MigrationsModel
|
||||
*/
|
||||
public function getByField(string $field, $value, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?Models\MigrationsModel
|
||||
{
|
||||
/** @var TableGateways\MigrationsTableGateway $migrationsTable */
|
||||
$migrationsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $migrationsTable->getByField($field, $value, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
* @param $limit int
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return null|Models\MigrationsModel[]
|
||||
*/
|
||||
public function getManyByField(string $field, $value, int $limit = null, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?array
|
||||
{
|
||||
/** @var TableGateways\MigrationsTableGateway $migrationsTable */
|
||||
$migrationsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $migrationsTable->getManyByField($field, $value, $limit, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countByField(string $field, $value): int
|
||||
{
|
||||
$migrationsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $migrationsTable->countByField($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Models\MigrationsModel
|
||||
*/
|
||||
public function getRandom(): ?Models\MigrationsModel
|
||||
{
|
||||
/** @var TableGateways\MigrationsTableGateway $migrationsTable */
|
||||
$migrationsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $migrationsTable->fetchRandom();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|\Closure|Predicate\PredicateInterface|string|Where $keyValue
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return Models\MigrationsModel
|
||||
*/
|
||||
public function getMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?Models\MigrationsModel
|
||||
{
|
||||
/** @var TableGateways\MigrationsTableGateway $migrationsTable */
|
||||
$migrationsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $migrationsTable->getMatching($keyValue, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|\Closure|Predicate\PredicateInterface|string|Where $keyValue
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
* @param $limit int Limit the number of matches returned
|
||||
*
|
||||
* @return Models\MigrationsModel[]
|
||||
*/
|
||||
public function getManyMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING, int $limit = null): ?array
|
||||
{
|
||||
/** @var TableGateways\MigrationsTableGateway $migrationsTable */
|
||||
$migrationsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $migrationsTable->getManyMatching($keyValue, $orderBy, $orderDirection, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dataExchange
|
||||
*
|
||||
* @return Models\MigrationsModel
|
||||
*/
|
||||
public function createFromArray($dataExchange): Models\MigrationsModel
|
||||
{
|
||||
/** @var TableGateways\MigrationsTableGateway $migrationsTable */
|
||||
$migrationsTable = $this->getNewTableGatewayInstance();
|
||||
$migrations = $this->getNewModelInstance($dataExchange);
|
||||
|
||||
return $migrationsTable->save($migrations);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function deleteByField(string $field, $value): int
|
||||
{
|
||||
/** @var TableGateways\MigrationsTableGateway $migrationsTable */
|
||||
$migrationsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $migrationsTable->delete([$field => $value]);
|
||||
}
|
||||
|
||||
public function getTermPlural(): string
|
||||
{
|
||||
return 'Migrations';
|
||||
}
|
||||
|
||||
public function getTermSingular(): string
|
||||
{
|
||||
return 'Migrations';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a version of this object pre-populated with nonsense.
|
||||
*
|
||||
* @returns Models\MigrationsModel
|
||||
*/
|
||||
public function getMockObject(): Models\MigrationsModel
|
||||
{
|
||||
return $this->getNewTableGatewayInstance()->getNewMockModelInstance();
|
||||
}
|
||||
}
|
218
test/app/src/Services/Base/BaseUsersService.php
Executable file
218
test/app/src/Services/Base/BaseUsersService.php
Executable file
|
@ -0,0 +1,218 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\Services\Base;
|
||||
|
||||
use Benzine\ORM\Tests\Models;
|
||||
use Benzine\ORM\Tests\TableGateways;
|
||||
use Laminas\Db\Sql\Expression;
|
||||
use Laminas\Db\Sql\Select;
|
||||
use Laminas\Db\Sql\Predicate;
|
||||
use Laminas\Db\Sql\Where;
|
||||
use Benzine\ORM\Abstracts\Service as AbstractService;
|
||||
use Benzine\ORM\Interfaces\ServiceInterface as ServiceInterface;
|
||||
|
||||
/** ___ __
|
||||
* / _ \___ ____ ___ ____ ____/ /
|
||||
* / // / _ `/ _ \/ _ `/ -_) __/_/
|
||||
* /____/\_,_/_//_/\_, /\__/_/ (_)
|
||||
* /___/.
|
||||
*
|
||||
* Anything in this file is prone to being overwritten!
|
||||
*
|
||||
* This file was programmatically generated. To modify
|
||||
* this classes behaviours, do so in the class that
|
||||
* extends this, or modify the Laminator Template!
|
||||
*/
|
||||
abstract class BaseUsersService extends AbstractService implements ServiceInterface
|
||||
{
|
||||
// Related Objects Table Gateways
|
||||
|
||||
// Remote Constraints Table Gateways
|
||||
|
||||
// Self Table Gateway
|
||||
protected TableGateways\UsersTableGateway $usersTableGateway;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param TableGateways\UsersTableGateway $usersTableGateway
|
||||
*/
|
||||
public function __construct(
|
||||
TableGateways\UsersTableGateway $usersTableGateway
|
||||
) {
|
||||
$this->usersTableGateway = $usersTableGateway;
|
||||
}
|
||||
|
||||
public function getNewTableGatewayInstance(): TableGateways\UsersTableGateway
|
||||
{
|
||||
return $this->usersTableGateway;
|
||||
}
|
||||
|
||||
public function getNewModelInstance($dataExchange = []): Models\UsersModel
|
||||
{
|
||||
return $this->usersTableGateway->getNewModelInstance($dataExchange);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|int $limit
|
||||
* @param null|int $offset
|
||||
* @param null|array|\Closure[] $wheres
|
||||
* @param null|Expression|string $order
|
||||
* @param null|string $orderDirection
|
||||
*
|
||||
* @return Models\UsersModel[]
|
||||
*/
|
||||
public function getAll(
|
||||
int $limit = null,
|
||||
int $offset = null,
|
||||
array $wheres = null,
|
||||
$order = null,
|
||||
string $orderDirection = null
|
||||
) {
|
||||
return parent::getAll(
|
||||
$limit,
|
||||
$offset,
|
||||
$wheres,
|
||||
$order,
|
||||
$orderDirection
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return null|Models\UsersModel
|
||||
*/
|
||||
public function getByField(string $field, $value, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?Models\UsersModel
|
||||
{
|
||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
||||
$usersTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $usersTable->getByField($field, $value, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
* @param $limit int
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return null|Models\UsersModel[]
|
||||
*/
|
||||
public function getManyByField(string $field, $value, int $limit = null, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?array
|
||||
{
|
||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
||||
$usersTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $usersTable->getManyByField($field, $value, $limit, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countByField(string $field, $value): int
|
||||
{
|
||||
$usersTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $usersTable->countByField($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Models\UsersModel
|
||||
*/
|
||||
public function getRandom(): ?Models\UsersModel
|
||||
{
|
||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
||||
$usersTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $usersTable->fetchRandom();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|\Closure|Predicate\PredicateInterface|string|Where $keyValue
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return Models\UsersModel
|
||||
*/
|
||||
public function getMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?Models\UsersModel
|
||||
{
|
||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
||||
$usersTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $usersTable->getMatching($keyValue, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|\Closure|Predicate\PredicateInterface|string|Where $keyValue
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
* @param $limit int Limit the number of matches returned
|
||||
*
|
||||
* @return Models\UsersModel[]
|
||||
*/
|
||||
public function getManyMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING, int $limit = null): ?array
|
||||
{
|
||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
||||
$usersTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $usersTable->getManyMatching($keyValue, $orderBy, $orderDirection, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dataExchange
|
||||
*
|
||||
* @return Models\UsersModel
|
||||
*/
|
||||
public function createFromArray($dataExchange): Models\UsersModel
|
||||
{
|
||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
||||
$usersTable = $this->getNewTableGatewayInstance();
|
||||
$users = $this->getNewModelInstance($dataExchange);
|
||||
|
||||
return $usersTable->save($users);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function deleteByField(string $field, $value): int
|
||||
{
|
||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
||||
$usersTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $usersTable->delete([$field => $value]);
|
||||
}
|
||||
|
||||
public function getTermPlural(): string
|
||||
{
|
||||
return 'Users';
|
||||
}
|
||||
|
||||
public function getTermSingular(): string
|
||||
{
|
||||
return 'Users';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a version of this object pre-populated with nonsense.
|
||||
*
|
||||
* @returns Models\UsersModel
|
||||
*/
|
||||
public function getMockObject(): Models\UsersModel
|
||||
{
|
||||
return $this->getNewTableGatewayInstance()->getNewMockModelInstance();
|
||||
}
|
||||
}
|
7
test/app/src/Services/BlogPostsService.php
Executable file
7
test/app/src/Services/BlogPostsService.php
Executable file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
namespace Benzine\ORM\Tests\Services;
|
||||
|
||||
class BlogPostsService extends Base\BaseBlogPostsService
|
||||
{
|
||||
|
||||
}
|
7
test/app/src/Services/MigrationsService.php
Executable file
7
test/app/src/Services/MigrationsService.php
Executable file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
namespace Benzine\ORM\Tests\Services;
|
||||
|
||||
class MigrationsService extends Base\BaseMigrationsService
|
||||
{
|
||||
|
||||
}
|
7
test/app/src/Services/UsersService.php
Executable file
7
test/app/src/Services/UsersService.php
Executable file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
namespace Benzine\ORM\Tests\Services;
|
||||
|
||||
class UsersService extends Base\BaseUsersService
|
||||
{
|
||||
|
||||
}
|
105
test/app/src/TableGateways/Base/BaseBlogPostsTableGateway.php
Executable file
105
test/app/src/TableGateways/Base/BaseBlogPostsTableGateway.php
Executable file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\TableGateways\Base;
|
||||
|
||||
use Benzine\ORM\Tests\Models;
|
||||
use Benzine\ORM\Tests\TableGateways;
|
||||
use Faker\Generator;
|
||||
use Laminas\Db\ResultSet\ResultSet;
|
||||
use Benzine\ORM\Abstracts\Model;
|
||||
use Benzine\ORM\Abstracts\TableGateway as AbstractTableGateway;
|
||||
use Benzine\ORM\Connection;
|
||||
use Benzine\ORM\Interfaces\TableGatewayInterface as TableGatewayInterface;
|
||||
use Benzine\Exceptions\BenzineException;
|
||||
|
||||
/** ___ __
|
||||
* / _ \___ ____ ___ ____ ____/ /
|
||||
* / // / _ `/ _ \/ _ `/ -_) __/_/
|
||||
* /____/\_,_/_//_/\_, /\__/_/ (_)
|
||||
* /___/.
|
||||
*
|
||||
* Anything in this file is prone to being overwritten!
|
||||
*
|
||||
* This file was programmatically generated. To modify
|
||||
* this classes behaviours, do so in the class that
|
||||
* extends this, or modify the Laminator Template!
|
||||
*/
|
||||
abstract class BaseBlogPostsTableGateway extends AbstractTableGateway implements TableGatewayInterface
|
||||
{
|
||||
protected $table = 'BlogPosts';
|
||||
//protected string $database = 'default';
|
||||
protected string $model = Models\BlogPostsModel::class;
|
||||
protected Generator $faker;
|
||||
protected Connection\Databases $databaseConnection;
|
||||
protected Connection\Database $database;
|
||||
|
||||
protected TableGateways\UsersTableGateway $usersTableGateway;
|
||||
|
||||
/**
|
||||
* AbstractTableGateway constructor.
|
||||
*
|
||||
* @param TableGateways\UsersTableGateway $usersTableGateway,
|
||||
* @param Generator $faker
|
||||
* @param Connection\Databases $databaseConnection
|
||||
*
|
||||
* @throws BenzineException
|
||||
*/
|
||||
public function __construct(
|
||||
TableGateways\UsersTableGateway $usersTableGateway,
|
||||
Generator $faker,
|
||||
Connection\Databases $databaseConnection
|
||||
) {
|
||||
$this->usersTableGateway = $usersTableGateway;
|
||||
$this->faker = $faker;
|
||||
$this->databaseConnection = $databaseConnection;
|
||||
$this->database = $this->databaseConnection->getDatabase('default');
|
||||
|
||||
$resultSetPrototype = new ResultSet(ResultSet::TYPE_ARRAYOBJECT, new $this->model());
|
||||
|
||||
parent::__construct($this->table, $this->database->getAdapter(), null, $resultSetPrototype);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Models\BlogPostsModel
|
||||
*/
|
||||
public function getNewMockModelInstance()
|
||||
{
|
||||
// Generate a Random Users.
|
||||
$randomUsers = $this->usersTableGateway->fetchRandom();
|
||||
|
||||
return $this->getNewModelInstance([
|
||||
// blogPostId. Type = int. PHPType = int. Has no related objects. Default is literal null
|
||||
// created. Type = timestamp. PHPType = string. Has no related objects. Default is interpreted current_timestamp()
|
||||
'created' => $this->faker->dateTime()->format("Y-m-d H:i:s"), // @todo: Make datetime fields accept DateTime objects instead of strings. - MB
|
||||
// description. Type = text. PHPType = string. Has no related objects. Default is literal null
|
||||
'description' => substr($this->faker->text(500), 0, 500),
|
||||
// title. Type = varchar. PHPType = string. Has no related objects. Default is literal null
|
||||
'title' => substr($this->faker->text(64), 0, 64),
|
||||
// userId. Type = int. PHPType = int. Has related objects. Default is literal null
|
||||
'userId' =>
|
||||
$randomUsers instanceof Models\UsersModel
|
||||
? $this->usersTableGateway->fetchRandom()->getUserId()
|
||||
: $this->usersTableGateway->getNewMockModelInstance()->save()->getUserId(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Models\BlogPostsModel
|
||||
*/
|
||||
public function getNewModelInstance(array $data = []): Models\BlogPostsModel
|
||||
{
|
||||
return parent::getNewModelInstance($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Models\BlogPostsModel $model
|
||||
*
|
||||
* @return Models\BlogPostsModel
|
||||
*/
|
||||
public function save(Model $model): Models\BlogPostsModel
|
||||
{
|
||||
return parent::save($model);
|
||||
}
|
||||
}
|
95
test/app/src/TableGateways/Base/BaseMigrationsTableGateway.php
Executable file
95
test/app/src/TableGateways/Base/BaseMigrationsTableGateway.php
Executable file
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\TableGateways\Base;
|
||||
|
||||
use Benzine\ORM\Tests\Models;
|
||||
use Benzine\ORM\Tests\TableGateways;
|
||||
use Faker\Generator;
|
||||
use Laminas\Db\ResultSet\ResultSet;
|
||||
use Benzine\ORM\Abstracts\Model;
|
||||
use Benzine\ORM\Abstracts\TableGateway as AbstractTableGateway;
|
||||
use Benzine\ORM\Connection;
|
||||
use Benzine\ORM\Interfaces\TableGatewayInterface as TableGatewayInterface;
|
||||
use Benzine\Exceptions\BenzineException;
|
||||
|
||||
/** ___ __
|
||||
* / _ \___ ____ ___ ____ ____/ /
|
||||
* / // / _ `/ _ \/ _ `/ -_) __/_/
|
||||
* /____/\_,_/_//_/\_, /\__/_/ (_)
|
||||
* /___/.
|
||||
*
|
||||
* Anything in this file is prone to being overwritten!
|
||||
*
|
||||
* This file was programmatically generated. To modify
|
||||
* this classes behaviours, do so in the class that
|
||||
* extends this, or modify the Laminator Template!
|
||||
*/
|
||||
abstract class BaseMigrationsTableGateway extends AbstractTableGateway implements TableGatewayInterface
|
||||
{
|
||||
protected $table = 'Migrations';
|
||||
//protected string $database = 'default';
|
||||
protected string $model = Models\MigrationsModel::class;
|
||||
protected Generator $faker;
|
||||
protected Connection\Databases $databaseConnection;
|
||||
protected Connection\Database $database;
|
||||
|
||||
/**
|
||||
* AbstractTableGateway constructor.
|
||||
*
|
||||
* @param Generator $faker
|
||||
* @param Connection\Databases $databaseConnection
|
||||
*
|
||||
* @throws BenzineException
|
||||
*/
|
||||
public function __construct(
|
||||
Generator $faker,
|
||||
Connection\Databases $databaseConnection
|
||||
) {
|
||||
$this->faker = $faker;
|
||||
$this->databaseConnection = $databaseConnection;
|
||||
$this->database = $this->databaseConnection->getDatabase('default');
|
||||
|
||||
$resultSetPrototype = new ResultSet(ResultSet::TYPE_ARRAYOBJECT, new $this->model());
|
||||
|
||||
parent::__construct($this->table, $this->database->getAdapter(), null, $resultSetPrototype);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Models\MigrationsModel
|
||||
*/
|
||||
public function getNewMockModelInstance()
|
||||
{
|
||||
return $this->getNewModelInstance([
|
||||
// breakpoint. Type = tinyint. PHPType = int. Has no related objects. Default is literal null
|
||||
'breakpoint' => $this->faker->numberBetween(1, 0.01),
|
||||
// end_time. Type = timestamp. PHPType = string. Has no related objects. Default is literal NULL
|
||||
'end_time' => $this->faker->dateTime()->format("Y-m-d H:i:s"), // @todo: Make datetime fields accept DateTime objects instead of strings. - MB
|
||||
// migration_name. Type = varchar. PHPType = string. Has no related objects. Default is literal NULL
|
||||
'migration_name' => substr($this->faker->text(100), 0, 100),
|
||||
// start_time. Type = timestamp. PHPType = string. Has no related objects. Default is literal NULL
|
||||
'start_time' => $this->faker->dateTime()->format("Y-m-d H:i:s"), // @todo: Make datetime fields accept DateTime objects instead of strings. - MB
|
||||
// version. Type = bigint. PHPType = int. Has no related objects. Default is literal null
|
||||
'version' => $this->faker->numberBetween(1, 0.01),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Models\MigrationsModel
|
||||
*/
|
||||
public function getNewModelInstance(array $data = []): Models\MigrationsModel
|
||||
{
|
||||
return parent::getNewModelInstance($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Models\MigrationsModel $model
|
||||
*
|
||||
* @return Models\MigrationsModel
|
||||
*/
|
||||
public function save(Model $model): Models\MigrationsModel
|
||||
{
|
||||
return parent::save($model);
|
||||
}
|
||||
}
|
92
test/app/src/TableGateways/Base/BaseUsersTableGateway.php
Executable file
92
test/app/src/TableGateways/Base/BaseUsersTableGateway.php
Executable file
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\TableGateways\Base;
|
||||
|
||||
use Benzine\ORM\Tests\Models;
|
||||
use Benzine\ORM\Tests\TableGateways;
|
||||
use Faker\Generator;
|
||||
use Laminas\Db\ResultSet\ResultSet;
|
||||
use Benzine\ORM\Abstracts\Model;
|
||||
use Benzine\ORM\Abstracts\TableGateway as AbstractTableGateway;
|
||||
use Benzine\ORM\Connection;
|
||||
use Benzine\ORM\Interfaces\TableGatewayInterface as TableGatewayInterface;
|
||||
use Benzine\Exceptions\BenzineException;
|
||||
|
||||
/** ___ __
|
||||
* / _ \___ ____ ___ ____ ____/ /
|
||||
* / // / _ `/ _ \/ _ `/ -_) __/_/
|
||||
* /____/\_,_/_//_/\_, /\__/_/ (_)
|
||||
* /___/.
|
||||
*
|
||||
* Anything in this file is prone to being overwritten!
|
||||
*
|
||||
* This file was programmatically generated. To modify
|
||||
* this classes behaviours, do so in the class that
|
||||
* extends this, or modify the Laminator Template!
|
||||
*/
|
||||
abstract class BaseUsersTableGateway extends AbstractTableGateway implements TableGatewayInterface
|
||||
{
|
||||
protected $table = 'Users';
|
||||
//protected string $database = 'default';
|
||||
protected string $model = Models\UsersModel::class;
|
||||
protected Generator $faker;
|
||||
protected Connection\Databases $databaseConnection;
|
||||
protected Connection\Database $database;
|
||||
|
||||
/**
|
||||
* AbstractTableGateway constructor.
|
||||
*
|
||||
* @param Generator $faker
|
||||
* @param Connection\Databases $databaseConnection
|
||||
*
|
||||
* @throws BenzineException
|
||||
*/
|
||||
public function __construct(
|
||||
Generator $faker,
|
||||
Connection\Databases $databaseConnection
|
||||
) {
|
||||
$this->faker = $faker;
|
||||
$this->databaseConnection = $databaseConnection;
|
||||
$this->database = $this->databaseConnection->getDatabase('default');
|
||||
|
||||
$resultSetPrototype = new ResultSet(ResultSet::TYPE_ARRAYOBJECT, new $this->model());
|
||||
|
||||
parent::__construct($this->table, $this->database->getAdapter(), null, $resultSetPrototype);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Models\UsersModel
|
||||
*/
|
||||
public function getNewMockModelInstance()
|
||||
{
|
||||
return $this->getNewModelInstance([
|
||||
// created. Type = timestamp. PHPType = string. Has no related objects. Default is interpreted current_timestamp()
|
||||
'created' => $this->faker->dateTime()->format("Y-m-d H:i:s"), // @todo: Make datetime fields accept DateTime objects instead of strings. - MB
|
||||
// email. Type = varchar. PHPType = string. Has no related objects. Default is literal null
|
||||
'email' => substr($this->faker->text(320), 0, 320),
|
||||
// name. Type = varchar. PHPType = string. Has no related objects. Default is literal null
|
||||
'name' => substr($this->faker->text(32), 0, 32),
|
||||
// userId. Type = int. PHPType = int. Has no related objects. Default is literal null
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Models\UsersModel
|
||||
*/
|
||||
public function getNewModelInstance(array $data = []): Models\UsersModel
|
||||
{
|
||||
return parent::getNewModelInstance($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Models\UsersModel $model
|
||||
*
|
||||
* @return Models\UsersModel
|
||||
*/
|
||||
public function save(Model $model): Models\UsersModel
|
||||
{
|
||||
return parent::save($model);
|
||||
}
|
||||
}
|
7
test/app/src/TableGateways/BlogPostsTableGateway.php
Executable file
7
test/app/src/TableGateways/BlogPostsTableGateway.php
Executable file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
namespace Benzine\ORM\Tests\TableGateways;
|
||||
|
||||
class BlogPostsTableGateway extends Base\BaseBlogPostsTableGateway
|
||||
{
|
||||
|
||||
}
|
7
test/app/src/TableGateways/MigrationsTableGateway.php
Executable file
7
test/app/src/TableGateways/MigrationsTableGateway.php
Executable file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
namespace Benzine\ORM\Tests\TableGateways;
|
||||
|
||||
class MigrationsTableGateway extends Base\BaseMigrationsTableGateway
|
||||
{
|
||||
|
||||
}
|
7
test/app/src/TableGateways/UsersTableGateway.php
Executable file
7
test/app/src/TableGateways/UsersTableGateway.php
Executable file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
namespace Benzine\ORM\Tests\TableGateways;
|
||||
|
||||
class UsersTableGateway extends Base\BaseUsersTableGateway
|
||||
{
|
||||
|
||||
}
|
212
test/app/tests/Models/Generated/BlogPostsTest.php
Executable file
212
test/app/tests/Models/Generated/BlogPostsTest.php
Executable file
|
@ -0,0 +1,212 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\Test\Models\Generated;
|
||||
|
||||
use Benzine\ORM\Tests\App as App;
|
||||
use Benzine\ORM\Tests\Models;
|
||||
use Benzine\ORM\Tests\Models\BlogPostsModel;
|
||||
use Benzine\ORM\Tests\TableGateways;
|
||||
use Benzine\ORM\Tests\TableGateways\BlogPostsTableGateway;
|
||||
use Gone\UUID\UUID;
|
||||
use Benzine\Tests\BaseTestCase;
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Models\BlogPostsModel
|
||||
* @covers \Benzine\ORM\Tests\Models\Base\BaseBlogPostsModel
|
||||
* @covers \Benzine\ORM\Tests\TableGateways\BlogPostsTableGateway
|
||||
* @covers \Benzine\ORM\Tests\TableGateways\Base\BaseBlogPostsTableGateway
|
||||
*
|
||||
* @group generated
|
||||
* @group models
|
||||
* @internal
|
||||
*/
|
||||
class BlogPostsTest extends BaseTestCase
|
||||
{
|
||||
protected BlogPostsModel $testInstance;
|
||||
protected BlogPostsTableGateway$testTableGateway;
|
||||
|
||||
/**
|
||||
* @before
|
||||
*/
|
||||
public function setupDependencies(): void
|
||||
{
|
||||
$this->testTableGateway = App::DI(BlogPostsTableGateway::class);
|
||||
$this->testInstance = $this->testTableGateway->getNewMockModelInstance();
|
||||
}
|
||||
|
||||
public function testExchangeArray()
|
||||
{
|
||||
$data = [];
|
||||
$data['blogPostId'] = self::getFaker()->randomDigitNotNull;
|
||||
$data['title'] = self::getFaker()->word;
|
||||
$data['description'] = self::getFaker()->word;
|
||||
$data['userId'] = self::getFaker()->randomDigitNotNull;
|
||||
$data['created'] = self::getFaker()->word;
|
||||
$this->testInstance = new BlogPostsModel($data);
|
||||
$this->assertEquals($data['blogPostId'], $this->testInstance->getBlogPostId());
|
||||
$this->assertEquals($data['title'], $this->testInstance->getTitle());
|
||||
$this->assertEquals($data['description'], $this->testInstance->getDescription());
|
||||
$this->assertEquals($data['userId'], $this->testInstance->getUserId());
|
||||
$this->assertEquals($data['created'], $this->testInstance->getCreated());
|
||||
}
|
||||
|
||||
public function testGetRandom()
|
||||
{
|
||||
// If there is no data in the table, create some.
|
||||
if (0 == $this->testTableGateway->getCount()) {
|
||||
$dummyObject = $this->testTableGateway->getNewMockModelInstance();
|
||||
$this->testTableGateway->save($dummyObject);
|
||||
}
|
||||
|
||||
$blogPost = $this->testTableGateway->fetchRandom();
|
||||
$this->assertTrue($blogPost instanceof BlogPostsModel, 'Make sure that "'.get_class($blogPost).'" matches "BlogPostsModel"');
|
||||
|
||||
return $blogPost;
|
||||
}
|
||||
|
||||
public function testNewMockModelInstance()
|
||||
{
|
||||
$new = $this->testTableGateway->getNewMockModelInstance();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Models\BlogPostsModel::class,
|
||||
$new
|
||||
);
|
||||
|
||||
$new->save();
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
public function testNewModelFactory()
|
||||
{
|
||||
$instance = BlogPostsModel::factory();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Models\BlogPostsModel::class,
|
||||
$instance
|
||||
);
|
||||
}
|
||||
|
||||
public function testSave()
|
||||
{
|
||||
/** @var Models\BlogPostsModel $mockModel */
|
||||
/** @var Models\BlogPostsModel $savedModel */
|
||||
$mockModel = $this->testTableGateway->getNewMockModelInstance();
|
||||
$savedModel = $mockModel->save();
|
||||
|
||||
$mockModelArray = $mockModel->__toArray();
|
||||
$savedModelArray = $savedModel->__toArray();
|
||||
|
||||
// Remove auto increments from test.
|
||||
foreach ($mockModel->getAutoIncrementKeys() as $autoIncrementKey => $discard) {
|
||||
foreach ($mockModelArray as $key => $value) {
|
||||
if (strtolower($key) == strtolower($autoIncrementKey)) {
|
||||
unset($mockModelArray[$key], $savedModelArray[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Remove non-literal fields from comparison - these will be autogenerated by the server and is outside the scope of this test.
|
||||
unset($mockModelArray['Created'], $savedModelArray['Created']);
|
||||
|
||||
$this->assertEquals($mockModelArray, $savedModelArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
*/
|
||||
public function testSettersAndGetters(BlogPostsModel $blogPosts)
|
||||
{
|
||||
$this->assertTrue(method_exists($blogPosts, 'getblogPostId'));
|
||||
$this->assertTrue(method_exists($blogPosts, 'setblogPostId'));
|
||||
$this->assertTrue(method_exists($blogPosts, 'gettitle'));
|
||||
$this->assertTrue(method_exists($blogPosts, 'settitle'));
|
||||
$this->assertTrue(method_exists($blogPosts, 'getdescription'));
|
||||
$this->assertTrue(method_exists($blogPosts, 'setdescription'));
|
||||
$this->assertTrue(method_exists($blogPosts, 'getuserId'));
|
||||
$this->assertTrue(method_exists($blogPosts, 'setuserId'));
|
||||
$this->assertTrue(method_exists($blogPosts, 'getcreated'));
|
||||
$this->assertTrue(method_exists($blogPosts, 'setcreated'));
|
||||
|
||||
$testBlogPosts = new BlogPostsModel();
|
||||
$input = self::getFaker()->randomDigitNotNull;
|
||||
$testBlogPosts->setBlogPostId($input);
|
||||
$this->assertEquals($input, $testBlogPosts->getBlogPostId());
|
||||
$input = self::getFaker()->word;
|
||||
$testBlogPosts->setTitle($input);
|
||||
$this->assertEquals($input, $testBlogPosts->getTitle());
|
||||
$input = self::getFaker()->word;
|
||||
$testBlogPosts->setDescription($input);
|
||||
$this->assertEquals($input, $testBlogPosts->getDescription());
|
||||
$input = self::getFaker()->randomDigitNotNull;
|
||||
$testBlogPosts->setUserId($input);
|
||||
$this->assertEquals($input, $testBlogPosts->getUserId());
|
||||
$input = self::getFaker()->word;
|
||||
$testBlogPosts->setCreated($input);
|
||||
$this->assertEquals($input, $testBlogPosts->getCreated());
|
||||
}
|
||||
|
||||
public function testAutoincrementedIdIsApplied()
|
||||
{
|
||||
$new = $this->testTableGateway->getNewMockModelInstance();
|
||||
|
||||
// Set primary keys to null.
|
||||
$new->setblogPostId(null);
|
||||
|
||||
// Save the object
|
||||
$saved = $new->save();
|
||||
|
||||
// verify that the AI keys have been set.
|
||||
$this->assertNotNull($saved->getblogPostId());
|
||||
$this->assertGreaterThan(0, $saved->getblogPostId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @large
|
||||
*/
|
||||
public function testDestroy()
|
||||
{
|
||||
/** @var Models\BlogPostsModel $destroyableModel */
|
||||
$destroyableModel = $this->testTableGateway->getNewMockModelInstance();
|
||||
$destroyableModel->save();
|
||||
$this->assertTrue(true, $destroyableModel->destroy());
|
||||
}
|
||||
|
||||
/**
|
||||
* @large
|
||||
*/
|
||||
public function testDestroyThoroughly()
|
||||
{
|
||||
/** @var Models\BlogPostsModel $destroyableModel */
|
||||
$destroyableModel = $this->testTableGateway->getNewMockModelInstance();
|
||||
$destroyableModel->save();
|
||||
$this->assertGreaterThan(0, $destroyableModel->destroyThoroughly());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @depends testNewMockModelInstance
|
||||
*/
|
||||
public function test_RelatedObjects_FetchUserObject(BlogPostsModel $blogPost)
|
||||
{
|
||||
// Verify the function exists
|
||||
$this->assertTrue(method_exists($blogPost, "fetchUserObject"));
|
||||
|
||||
// Call the function on it
|
||||
$blogPostModel = $blogPost->fetchUserObject();
|
||||
|
||||
$this->assertInstanceOf(Models\UsersModel::class, $blogPostModel);
|
||||
}
|
||||
|
||||
public function testGetPropertyMeta()
|
||||
{
|
||||
$propertyMeta = $this->testInstance->getPropertyMeta();
|
||||
$this->assertTrue(is_array($propertyMeta));
|
||||
$this->assertGreaterThan(0, count($propertyMeta));
|
||||
$this->assertArrayHasKey(BlogPostsModel::FIELD_BLOGPOSTID, $propertyMeta);
|
||||
$this->assertArrayHasKey(BlogPostsModel::FIELD_TITLE, $propertyMeta);
|
||||
$this->assertArrayHasKey(BlogPostsModel::FIELD_DESCRIPTION, $propertyMeta);
|
||||
$this->assertArrayHasKey(BlogPostsModel::FIELD_USERID, $propertyMeta);
|
||||
$this->assertArrayHasKey(BlogPostsModel::FIELD_CREATED, $propertyMeta);
|
||||
}
|
||||
}
|
180
test/app/tests/Models/Generated/MigrationsTest.php
Executable file
180
test/app/tests/Models/Generated/MigrationsTest.php
Executable file
|
@ -0,0 +1,180 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\Test\Models\Generated;
|
||||
|
||||
use Benzine\ORM\Tests\App as App;
|
||||
use Benzine\ORM\Tests\Models;
|
||||
use Benzine\ORM\Tests\Models\MigrationsModel;
|
||||
use Benzine\ORM\Tests\TableGateways;
|
||||
use Benzine\ORM\Tests\TableGateways\MigrationsTableGateway;
|
||||
use Gone\UUID\UUID;
|
||||
use Benzine\Tests\BaseTestCase;
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Models\MigrationsModel
|
||||
* @covers \Benzine\ORM\Tests\Models\Base\BaseMigrationsModel
|
||||
* @covers \Benzine\ORM\Tests\TableGateways\MigrationsTableGateway
|
||||
* @covers \Benzine\ORM\Tests\TableGateways\Base\BaseMigrationsTableGateway
|
||||
*
|
||||
* @group generated
|
||||
* @group models
|
||||
* @internal
|
||||
*/
|
||||
class MigrationsTest extends BaseTestCase
|
||||
{
|
||||
protected MigrationsModel $testInstance;
|
||||
protected MigrationsTableGateway$testTableGateway;
|
||||
|
||||
/**
|
||||
* @before
|
||||
*/
|
||||
public function setupDependencies(): void
|
||||
{
|
||||
$this->testTableGateway = App::DI(MigrationsTableGateway::class);
|
||||
$this->testInstance = $this->testTableGateway->getNewMockModelInstance();
|
||||
}
|
||||
|
||||
public function testExchangeArray()
|
||||
{
|
||||
$data = [];
|
||||
$data['version'] = self::getFaker()->randomDigitNotNull;
|
||||
$data['migration_name'] = self::getFaker()->word;
|
||||
$data['start_time'] = self::getFaker()->word;
|
||||
$data['end_time'] = self::getFaker()->word;
|
||||
$data['breakpoint'] = self::getFaker()->randomDigitNotNull;
|
||||
$this->testInstance = new MigrationsModel($data);
|
||||
$this->assertEquals($data['version'], $this->testInstance->getVersion());
|
||||
$this->assertEquals($data['migration_name'], $this->testInstance->getMigration_name());
|
||||
$this->assertEquals($data['start_time'], $this->testInstance->getStart_time());
|
||||
$this->assertEquals($data['end_time'], $this->testInstance->getEnd_time());
|
||||
$this->assertEquals($data['breakpoint'], $this->testInstance->getBreakpoint());
|
||||
}
|
||||
|
||||
public function testGetRandom()
|
||||
{
|
||||
// If there is no data in the table, create some.
|
||||
if (0 == $this->testTableGateway->getCount()) {
|
||||
$dummyObject = $this->testTableGateway->getNewMockModelInstance();
|
||||
$this->testTableGateway->save($dummyObject);
|
||||
}
|
||||
|
||||
$migration = $this->testTableGateway->fetchRandom();
|
||||
$this->assertTrue($migration instanceof MigrationsModel, 'Make sure that "'.get_class($migration).'" matches "MigrationsModel"');
|
||||
|
||||
return $migration;
|
||||
}
|
||||
|
||||
public function testNewMockModelInstance()
|
||||
{
|
||||
$new = $this->testTableGateway->getNewMockModelInstance();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Models\MigrationsModel::class,
|
||||
$new
|
||||
);
|
||||
|
||||
$new->save();
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
public function testNewModelFactory()
|
||||
{
|
||||
$instance = MigrationsModel::factory();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Models\MigrationsModel::class,
|
||||
$instance
|
||||
);
|
||||
}
|
||||
|
||||
public function testSave()
|
||||
{
|
||||
/** @var Models\MigrationsModel $mockModel */
|
||||
/** @var Models\MigrationsModel $savedModel */
|
||||
$mockModel = $this->testTableGateway->getNewMockModelInstance();
|
||||
$savedModel = $mockModel->save();
|
||||
|
||||
$mockModelArray = $mockModel->__toArray();
|
||||
$savedModelArray = $savedModel->__toArray();
|
||||
|
||||
// Remove auto increments from test.
|
||||
foreach ($mockModel->getAutoIncrementKeys() as $autoIncrementKey => $discard) {
|
||||
foreach ($mockModelArray as $key => $value) {
|
||||
if (strtolower($key) == strtolower($autoIncrementKey)) {
|
||||
unset($mockModelArray[$key], $savedModelArray[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals($mockModelArray, $savedModelArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
*/
|
||||
public function testSettersAndGetters(MigrationsModel $migrations)
|
||||
{
|
||||
$this->assertTrue(method_exists($migrations, 'getversion'));
|
||||
$this->assertTrue(method_exists($migrations, 'setversion'));
|
||||
$this->assertTrue(method_exists($migrations, 'getmigration_name'));
|
||||
$this->assertTrue(method_exists($migrations, 'setmigration_name'));
|
||||
$this->assertTrue(method_exists($migrations, 'getstart_time'));
|
||||
$this->assertTrue(method_exists($migrations, 'setstart_time'));
|
||||
$this->assertTrue(method_exists($migrations, 'getend_time'));
|
||||
$this->assertTrue(method_exists($migrations, 'setend_time'));
|
||||
$this->assertTrue(method_exists($migrations, 'getbreakpoint'));
|
||||
$this->assertTrue(method_exists($migrations, 'setbreakpoint'));
|
||||
|
||||
$testMigrations = new MigrationsModel();
|
||||
$input = self::getFaker()->randomDigitNotNull;
|
||||
$testMigrations->setVersion($input);
|
||||
$this->assertEquals($input, $testMigrations->getVersion());
|
||||
$input = self::getFaker()->word;
|
||||
$testMigrations->setMigration_name($input);
|
||||
$this->assertEquals($input, $testMigrations->getMigration_name());
|
||||
$input = self::getFaker()->word;
|
||||
$testMigrations->setStart_time($input);
|
||||
$this->assertEquals($input, $testMigrations->getStart_time());
|
||||
$input = self::getFaker()->word;
|
||||
$testMigrations->setEnd_time($input);
|
||||
$this->assertEquals($input, $testMigrations->getEnd_time());
|
||||
$input = self::getFaker()->randomDigitNotNull;
|
||||
$testMigrations->setBreakpoint($input);
|
||||
$this->assertEquals($input, $testMigrations->getBreakpoint());
|
||||
}
|
||||
|
||||
/**
|
||||
* @large
|
||||
*/
|
||||
public function testDestroy()
|
||||
{
|
||||
/** @var Models\MigrationsModel $destroyableModel */
|
||||
$destroyableModel = $this->testTableGateway->getNewMockModelInstance();
|
||||
$destroyableModel->save();
|
||||
$this->assertTrue(true, $destroyableModel->destroy());
|
||||
}
|
||||
|
||||
/**
|
||||
* @large
|
||||
*/
|
||||
public function testDestroyThoroughly()
|
||||
{
|
||||
/** @var Models\MigrationsModel $destroyableModel */
|
||||
$destroyableModel = $this->testTableGateway->getNewMockModelInstance();
|
||||
$destroyableModel->save();
|
||||
$this->assertGreaterThan(0, $destroyableModel->destroyThoroughly());
|
||||
}
|
||||
|
||||
public function testGetPropertyMeta()
|
||||
{
|
||||
$propertyMeta = $this->testInstance->getPropertyMeta();
|
||||
$this->assertTrue(is_array($propertyMeta));
|
||||
$this->assertGreaterThan(0, count($propertyMeta));
|
||||
$this->assertArrayHasKey(MigrationsModel::FIELD_VERSION, $propertyMeta);
|
||||
$this->assertArrayHasKey(MigrationsModel::FIELD_MIGRATION_NAME, $propertyMeta);
|
||||
$this->assertArrayHasKey(MigrationsModel::FIELD_START_TIME, $propertyMeta);
|
||||
$this->assertArrayHasKey(MigrationsModel::FIELD_END_TIME, $propertyMeta);
|
||||
$this->assertArrayHasKey(MigrationsModel::FIELD_BREAKPOINT, $propertyMeta);
|
||||
}
|
||||
}
|
246
test/app/tests/Models/Generated/UsersTest.php
Executable file
246
test/app/tests/Models/Generated/UsersTest.php
Executable file
|
@ -0,0 +1,246 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\Test\Models\Generated;
|
||||
|
||||
use Benzine\ORM\Tests\App as App;
|
||||
use Benzine\ORM\Tests\Models;
|
||||
use Benzine\ORM\Tests\Models\UsersModel;
|
||||
use Benzine\ORM\Tests\TableGateways;
|
||||
use Benzine\ORM\Tests\TableGateways\UsersTableGateway;
|
||||
use Gone\UUID\UUID;
|
||||
use Benzine\Tests\BaseTestCase;
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Models\UsersModel
|
||||
* @covers \Benzine\ORM\Tests\Models\Base\BaseUsersModel
|
||||
* @covers \Benzine\ORM\Tests\TableGateways\UsersTableGateway
|
||||
* @covers \Benzine\ORM\Tests\TableGateways\Base\BaseUsersTableGateway
|
||||
*
|
||||
* @group generated
|
||||
* @group models
|
||||
* @internal
|
||||
*/
|
||||
class UsersTest extends BaseTestCase
|
||||
{
|
||||
protected UsersModel $testInstance;
|
||||
protected UsersTableGateway$testTableGateway;
|
||||
|
||||
/**
|
||||
* @before
|
||||
*/
|
||||
public function setupDependencies(): void
|
||||
{
|
||||
$this->testTableGateway = App::DI(UsersTableGateway::class);
|
||||
$this->testInstance = $this->testTableGateway->getNewMockModelInstance();
|
||||
}
|
||||
|
||||
public function testExchangeArray()
|
||||
{
|
||||
$data = [];
|
||||
$data['userId'] = self::getFaker()->randomDigitNotNull;
|
||||
$data['name'] = self::getFaker()->word;
|
||||
$data['email'] = self::getFaker()->word;
|
||||
$data['created'] = self::getFaker()->word;
|
||||
$this->testInstance = new UsersModel($data);
|
||||
$this->assertEquals($data['userId'], $this->testInstance->getUserId());
|
||||
$this->assertEquals($data['name'], $this->testInstance->getName());
|
||||
$this->assertEquals($data['email'], $this->testInstance->getEmail());
|
||||
$this->assertEquals($data['created'], $this->testInstance->getCreated());
|
||||
}
|
||||
|
||||
public function testGetRandom()
|
||||
{
|
||||
// If there is no data in the table, create some.
|
||||
if (0 == $this->testTableGateway->getCount()) {
|
||||
$dummyObject = $this->testTableGateway->getNewMockModelInstance();
|
||||
$this->testTableGateway->save($dummyObject);
|
||||
}
|
||||
|
||||
$user = $this->testTableGateway->fetchRandom();
|
||||
$this->assertTrue($user instanceof UsersModel, 'Make sure that "'.get_class($user).'" matches "UsersModel"');
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function testNewMockModelInstance()
|
||||
{
|
||||
$new = $this->testTableGateway->getNewMockModelInstance();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Models\UsersModel::class,
|
||||
$new
|
||||
);
|
||||
|
||||
$new->save();
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
public function testNewModelFactory()
|
||||
{
|
||||
$instance = UsersModel::factory();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Models\UsersModel::class,
|
||||
$instance
|
||||
);
|
||||
}
|
||||
|
||||
public function testSave()
|
||||
{
|
||||
/** @var Models\UsersModel $mockModel */
|
||||
/** @var Models\UsersModel $savedModel */
|
||||
$mockModel = $this->testTableGateway->getNewMockModelInstance();
|
||||
$savedModel = $mockModel->save();
|
||||
|
||||
$mockModelArray = $mockModel->__toArray();
|
||||
$savedModelArray = $savedModel->__toArray();
|
||||
|
||||
// Remove auto increments from test.
|
||||
foreach ($mockModel->getAutoIncrementKeys() as $autoIncrementKey => $discard) {
|
||||
foreach ($mockModelArray as $key => $value) {
|
||||
if (strtolower($key) == strtolower($autoIncrementKey)) {
|
||||
unset($mockModelArray[$key], $savedModelArray[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Remove non-literal fields from comparison - these will be autogenerated by the server and is outside the scope of this test.
|
||||
unset($mockModelArray['Created'], $savedModelArray['Created']);
|
||||
|
||||
$this->assertEquals($mockModelArray, $savedModelArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
*/
|
||||
public function testSettersAndGetters(UsersModel $users)
|
||||
{
|
||||
$this->assertTrue(method_exists($users, 'getuserId'));
|
||||
$this->assertTrue(method_exists($users, 'setuserId'));
|
||||
$this->assertTrue(method_exists($users, 'getname'));
|
||||
$this->assertTrue(method_exists($users, 'setname'));
|
||||
$this->assertTrue(method_exists($users, 'getemail'));
|
||||
$this->assertTrue(method_exists($users, 'setemail'));
|
||||
$this->assertTrue(method_exists($users, 'getcreated'));
|
||||
$this->assertTrue(method_exists($users, 'setcreated'));
|
||||
|
||||
$testUsers = new UsersModel();
|
||||
$input = self::getFaker()->randomDigitNotNull;
|
||||
$testUsers->setUserId($input);
|
||||
$this->assertEquals($input, $testUsers->getUserId());
|
||||
$input = self::getFaker()->word;
|
||||
$testUsers->setName($input);
|
||||
$this->assertEquals($input, $testUsers->getName());
|
||||
$input = self::getFaker()->word;
|
||||
$testUsers->setEmail($input);
|
||||
$this->assertEquals($input, $testUsers->getEmail());
|
||||
$input = self::getFaker()->word;
|
||||
$testUsers->setCreated($input);
|
||||
$this->assertEquals($input, $testUsers->getCreated());
|
||||
}
|
||||
|
||||
public function testAutoincrementedIdIsApplied()
|
||||
{
|
||||
$new = $this->testTableGateway->getNewMockModelInstance();
|
||||
|
||||
// Set primary keys to null.
|
||||
$new->setuserId(null);
|
||||
|
||||
// Save the object
|
||||
$saved = $new->save();
|
||||
|
||||
// verify that the AI keys have been set.
|
||||
$this->assertNotNull($saved->getuserId());
|
||||
$this->assertGreaterThan(0, $saved->getuserId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @large
|
||||
*/
|
||||
public function testDestroy()
|
||||
{
|
||||
/** @var Models\UsersModel $destroyableModel */
|
||||
$destroyableModel = $this->testTableGateway->getNewMockModelInstance();
|
||||
$destroyableModel->save();
|
||||
$this->assertTrue(true, $destroyableModel->destroy());
|
||||
}
|
||||
|
||||
/**
|
||||
* @large
|
||||
*/
|
||||
public function testDestroyThoroughly()
|
||||
{
|
||||
/** @var Models\UsersModel $destroyableModel */
|
||||
$destroyableModel = $this->testTableGateway->getNewMockModelInstance();
|
||||
$destroyableModel->save();
|
||||
$this->assertGreaterThan(0, $destroyableModel->destroyThoroughly());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testNewMockModelInstance
|
||||
*/
|
||||
public function test_RemoteObjects_FetchBlogPostObjects(UsersModel $user)
|
||||
{
|
||||
// Verify the function exists
|
||||
$this->assertTrue(method_exists($user, "fetchBlogPostObjects"));
|
||||
|
||||
/** @var TableGateways\BlogPostsTableGateway $tableGateway */
|
||||
$tableGateway = App::DI(TableGateways\BlogPostsTableGateway::class);
|
||||
|
||||
$user->save();
|
||||
|
||||
$this->assertNotNull($user->getUserId());
|
||||
|
||||
/** @var Models\BlogPostsModel $newBlogPostsModel */
|
||||
$newBlogPostsModel = $tableGateway->getNewMockModelInstance();
|
||||
$newBlogPostsModel->setUserId($user->getUserId());
|
||||
|
||||
// Save our new model. Make offerings to the gods of phpunit & transaction rollback to clean it up afterwards.
|
||||
$newBlogPostsModel->save();
|
||||
$this->assertNotNull($newBlogPostsModel->getUserId());
|
||||
|
||||
// Call the singular function on it
|
||||
$blogPostsModel = $user->fetchBlogPostObject();
|
||||
|
||||
$this->assertInstanceOf(Models\BlogPostsModel::class, $blogPostsModel);
|
||||
|
||||
// Call the plural function on it
|
||||
$blogPostModels = $user->fetchBlogPostObjects();
|
||||
|
||||
$this->assertGreaterThanOrEqual(1, count($blogPostModels), "fetchBlogPostObjects() failed to return atleast 1 Models\BlogPostsModel.");
|
||||
$this->assertContainsOnlyInstancesOf(Models\BlogPostsModel::class, $blogPostModels);
|
||||
|
||||
return [$user, $blogPostModels];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_RemoteObjects_FetchBlogPostObjects
|
||||
*/
|
||||
public function test_RemoteObjects_CountBlogPostObjects($list)
|
||||
{
|
||||
/**
|
||||
* @var $user Models\UsersModel
|
||||
* @var $blogPostModels Models\BlogPostsModel[]
|
||||
*/
|
||||
list($user, $blogPostModels) = $list;
|
||||
|
||||
// Verify the function exists
|
||||
$this->assertTrue(method_exists($user, "countBlogPostObjects"));
|
||||
|
||||
// Call the function on it
|
||||
$count = $user->countBlogPostObjects();
|
||||
|
||||
$this->assertCount($count, $blogPostModels);
|
||||
}
|
||||
|
||||
public function testGetPropertyMeta()
|
||||
{
|
||||
$propertyMeta = $this->testInstance->getPropertyMeta();
|
||||
$this->assertTrue(is_array($propertyMeta));
|
||||
$this->assertGreaterThan(0, count($propertyMeta));
|
||||
$this->assertArrayHasKey(UsersModel::FIELD_USERID, $propertyMeta);
|
||||
$this->assertArrayHasKey(UsersModel::FIELD_NAME, $propertyMeta);
|
||||
$this->assertArrayHasKey(UsersModel::FIELD_EMAIL, $propertyMeta);
|
||||
$this->assertArrayHasKey(UsersModel::FIELD_CREATED, $propertyMeta);
|
||||
}
|
||||
}
|
393
test/app/tests/Services/Generated/BlogPostsTest.php
Executable file
393
test/app/tests/Services/Generated/BlogPostsTest.php
Executable file
|
@ -0,0 +1,393 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\Test\Services\Generated;
|
||||
|
||||
use Benzine\ORM\Tests\App as App;
|
||||
use Benzine\ORM\Tests\TableGateways\BlogPostsTableGateway;
|
||||
use Benzine\ORM\Tests\Services;
|
||||
use Benzine\ORM\Tests\Models\BlogPostsModel;
|
||||
use Laminas\Db\Sql\Select;
|
||||
use Laminas\Db\Sql\Where;
|
||||
use Benzine\Tests\BaseTestCase;
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Models\BlogPostsModel
|
||||
* @covers \Benzine\ORM\Tests\Models\Base\BaseBlogPostsModel
|
||||
* @covers \Benzine\ORM\Tests\Services\BlogPostsService
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseBlogPostsService
|
||||
* @covers \Benzine\ORM\Tests\TableGateways\BlogPostsTableGateway
|
||||
* @covers \Benzine\ORM\Tests\TableGateways\Base\BaseBlogPostsTableGateway
|
||||
*
|
||||
* @group generated
|
||||
* @group services
|
||||
* @internal
|
||||
**/
|
||||
class BlogPostsTest extends BaseTestCase
|
||||
{
|
||||
protected Services\BlogPostsService $blogPostsService;
|
||||
protected BlogPostsTableGateway $blogPostsTableGateway;
|
||||
|
||||
/** @var BlogPostsModel[] */
|
||||
private static array $MockData = [];
|
||||
|
||||
/**
|
||||
* @beforeClass
|
||||
*/
|
||||
public static function setupBlogPostsMockData(): void
|
||||
{
|
||||
/** @var BlogPostsTableGateway $blogPostsTableGateway */
|
||||
$blogPostsTableGateway = App::DI(BlogPostsTableGateway::class);
|
||||
for($i = 0; $i <= 5; $i++){
|
||||
self::$MockData[] = $blogPostsTableGateway
|
||||
->getNewMockModelInstance()
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @before
|
||||
*/
|
||||
public function setupBlogPostsService(): void
|
||||
{
|
||||
$this->blogPostsService = App::DI(Services\BlogPostsService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @before
|
||||
*/
|
||||
public function setupBlogPostsTableGateway(): void
|
||||
{
|
||||
$this->blogPostsTableGateway = App::DI(BlogPostsTableGateway::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseBlogPostsService::getNewModelInstance
|
||||
*/
|
||||
public function testGetNewModelInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
BlogPostsModel::class,
|
||||
$this->blogPostsService->getNewModelInstance()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @large
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseBlogPostsService::getAll
|
||||
*/
|
||||
public function testGetAll()
|
||||
{
|
||||
$all = $this->blogPostsService->getAll();
|
||||
$this->assertInstanceOf(
|
||||
BlogPostsModel::class,
|
||||
reset($all)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseBlogPostsService::getRandom
|
||||
*/
|
||||
public function testGetRandom()
|
||||
{
|
||||
$random = $this->blogPostsService->getRandom();
|
||||
$this->assertInstanceOf(
|
||||
BlogPostsModel::class,
|
||||
$random
|
||||
);
|
||||
|
||||
return $random;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseBlogPostsService::getByField
|
||||
*/
|
||||
public function testGetByPrimaryKeys(BlogPostsModel $random)
|
||||
{
|
||||
/** @var BlogPostsModel $found */
|
||||
// By blogPostId
|
||||
$found = $this->blogPostsService->getByField(BlogPostsModel::FIELD_BLOGPOSTID, $random->getblogPostId());
|
||||
$this->assertInstanceOf(
|
||||
BlogPostsModel::class,
|
||||
$found
|
||||
);
|
||||
$this->assertEquals($random, $found);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
*/
|
||||
public function testCreateFromArray(BlogPostsModel $random)
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
BlogPostsModel::class,
|
||||
$this->blogPostsService->createFromArray($random->__toArray())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseBlogPostsService::getMockObject
|
||||
*/
|
||||
public function testGetMockObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
BlogPostsModel::class,
|
||||
$this->blogPostsService->getMockObject()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseBlogPostsService::getByField
|
||||
*/
|
||||
public function testGetByField(BlogPostsModel $random)
|
||||
{
|
||||
$found = $this->blogPostsService->getByField(
|
||||
BlogPostsModel::FIELD_BLOGPOSTID,
|
||||
$random->getBlogPostId()
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
BlogPostsModel::class,
|
||||
$found,
|
||||
"Calling Services\\BlogPostsService->getByField((BlogPostsModel::FIELD_BLOGPOSTID) failed to find a BlogPostsModel"
|
||||
);
|
||||
$found = $this->blogPostsService->getByField(
|
||||
BlogPostsModel::FIELD_TITLE,
|
||||
$random->getTitle()
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
BlogPostsModel::class,
|
||||
$found,
|
||||
"Calling Services\\BlogPostsService->getByField((BlogPostsModel::FIELD_TITLE) failed to find a BlogPostsModel"
|
||||
);
|
||||
$found = $this->blogPostsService->getByField(
|
||||
BlogPostsModel::FIELD_DESCRIPTION,
|
||||
$random->getDescription()
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
BlogPostsModel::class,
|
||||
$found,
|
||||
"Calling Services\\BlogPostsService->getByField((BlogPostsModel::FIELD_DESCRIPTION) failed to find a BlogPostsModel"
|
||||
);
|
||||
$found = $this->blogPostsService->getByField(
|
||||
BlogPostsModel::FIELD_USERID,
|
||||
$random->getUserId()
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
BlogPostsModel::class,
|
||||
$found,
|
||||
"Calling Services\\BlogPostsService->getByField((BlogPostsModel::FIELD_USERID) failed to find a BlogPostsModel"
|
||||
);
|
||||
$found = $this->blogPostsService->getByField(
|
||||
BlogPostsModel::FIELD_CREATED,
|
||||
$random->getCreated()
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
BlogPostsModel::class,
|
||||
$found,
|
||||
"Calling Services\\BlogPostsService->getByField((BlogPostsModel::FIELD_CREATED) failed to find a BlogPostsModel"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseBlogPostsService::countByField
|
||||
*/
|
||||
public function testCountByField(BlogPostsModel $random)
|
||||
{
|
||||
$found = $this->blogPostsService->countByField(BlogPostsModel::FIELD_BLOGPOSTID, $random->getBlogPostId());
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
$found,
|
||||
"Calling Services\\BlogPostsService->countByField(BlogPostsModel::FIELD_BLOGPOSTID) failed to count a BlogPostsModel"
|
||||
);
|
||||
$found = $this->blogPostsService->countByField(BlogPostsModel::FIELD_TITLE, $random->getTitle());
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
$found,
|
||||
"Calling Services\\BlogPostsService->countByField(BlogPostsModel::FIELD_TITLE) failed to count a BlogPostsModel"
|
||||
);
|
||||
$found = $this->blogPostsService->countByField(BlogPostsModel::FIELD_DESCRIPTION, $random->getDescription());
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
$found,
|
||||
"Calling Services\\BlogPostsService->countByField(BlogPostsModel::FIELD_DESCRIPTION) failed to count a BlogPostsModel"
|
||||
);
|
||||
$found = $this->blogPostsService->countByField(BlogPostsModel::FIELD_USERID, $random->getUserId());
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
$found,
|
||||
"Calling Services\\BlogPostsService->countByField(BlogPostsModel::FIELD_USERID) failed to count a BlogPostsModel"
|
||||
);
|
||||
$found = $this->blogPostsService->countByField(BlogPostsModel::FIELD_CREATED, $random->getCreated());
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
$found,
|
||||
"Calling Services\\BlogPostsService->countByField(BlogPostsModel::FIELD_CREATED) failed to count a BlogPostsModel"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseBlogPostsService::getManyByField
|
||||
*/
|
||||
public function testGetManyByField(BlogPostsModel $random)
|
||||
{
|
||||
// Testing get by blogPostId
|
||||
$this->assertContainsOnlyInstancesOf(
|
||||
BlogPostsModel::class,
|
||||
$this->blogPostsService->getManyByField(
|
||||
BlogPostsModel::FIELD_BLOGPOSTID,
|
||||
$random->getblogPostId(),
|
||||
5
|
||||
)
|
||||
);
|
||||
// Testing get by title
|
||||
$this->assertContainsOnlyInstancesOf(
|
||||
BlogPostsModel::class,
|
||||
$this->blogPostsService->getManyByField(
|
||||
BlogPostsModel::FIELD_TITLE,
|
||||
$random->gettitle(),
|
||||
5
|
||||
)
|
||||
);
|
||||
// Testing get by description
|
||||
$this->assertContainsOnlyInstancesOf(
|
||||
BlogPostsModel::class,
|
||||
$this->blogPostsService->getManyByField(
|
||||
BlogPostsModel::FIELD_DESCRIPTION,
|
||||
$random->getdescription(),
|
||||
5
|
||||
)
|
||||
);
|
||||
// Testing get by userId
|
||||
$this->assertContainsOnlyInstancesOf(
|
||||
BlogPostsModel::class,
|
||||
$this->blogPostsService->getManyByField(
|
||||
BlogPostsModel::FIELD_USERID,
|
||||
$random->getuserId(),
|
||||
5
|
||||
)
|
||||
);
|
||||
// Testing get by created
|
||||
$this->assertContainsOnlyInstancesOf(
|
||||
BlogPostsModel::class,
|
||||
$this->blogPostsService->getManyByField(
|
||||
BlogPostsModel::FIELD_CREATED,
|
||||
$random->getcreated(),
|
||||
5
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function getMockDataFilter(): \Closure
|
||||
{
|
||||
$mockData = self::$MockData;
|
||||
return function (Where $where) use ($mockData) {
|
||||
$where
|
||||
->nest()
|
||||
->equalTo(BlogPostsModel::FIELD_BLOGPOSTID, $mockData[0]->getblogPostId())
|
||||
->or
|
||||
->equalTo(BlogPostsModel::FIELD_BLOGPOSTID, $mockData[1]->getblogPostId())
|
||||
->or
|
||||
->equalTo(BlogPostsModel::FIELD_BLOGPOSTID, $mockData[2]->getblogPostId())
|
||||
->or
|
||||
->equalTo(BlogPostsModel::FIELD_BLOGPOSTID, $mockData[3]->getblogPostId())
|
||||
->or
|
||||
->equalTo(BlogPostsModel::FIELD_BLOGPOSTID, $mockData[4]->getblogPostId())
|
||||
->or
|
||||
->equalTo(BlogPostsModel::FIELD_BLOGPOSTID, $mockData[5]->getblogPostId())
|
||||
->unnest()
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseBlogPostsService::getManyMatching
|
||||
*/
|
||||
public function testGetManyMatching(BlogPostsModel $random)
|
||||
{
|
||||
$filter = $this->getMockDataFilter();
|
||||
|
||||
$all = $this->blogPostsService->getManyMatching($filter);
|
||||
$this->assertGreaterThan(0, count($all));
|
||||
$this->assertContainsOnlyInstancesOf(BlogPostsModel::class, $all);
|
||||
|
||||
$one = $this->blogPostsService->getManyMatching($filter, null, Select::ORDER_ASCENDING, 1);
|
||||
$this->assertEquals(1, count($one));
|
||||
$this->assertContainsOnlyInstancesOf(BlogPostsModel::class, $one);
|
||||
|
||||
$asc = $this->blogPostsService->getMatching($filter, BlogPostsModel::FIELD_BLOGPOSTID, Select::ORDER_ASCENDING);
|
||||
$desc = $this->blogPostsService->getMatching($filter, BlogPostsModel::FIELD_BLOGPOSTID, Select::ORDER_DESCENDING);
|
||||
$this->assertEquals(blogPostsModel::class, get_class($asc));
|
||||
$this->assertEquals(blogPostsModel::class, get_class($desc));
|
||||
$this->assertNotEquals($asc, $desc);
|
||||
$this->assertEquals($random, $this->blogPostsService->getMatching([BlogPostsModel::FIELD_BLOGPOSTID => $random->getblogPostId()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseBlogPostsService::getMatching
|
||||
*/
|
||||
public function testGetMatching(BlogPostsModel $random)
|
||||
{
|
||||
$filter = $this->getMockDataFilter();
|
||||
|
||||
$all = $this->blogPostsService->getMatching($filter);
|
||||
$this->assertEquals(blogPostsModel::class, get_class($all));
|
||||
|
||||
$asc = $this->blogPostsService->getMatching($filter, BlogPostsModel::FIELD_BLOGPOSTID, Select::ORDER_ASCENDING);
|
||||
$desc = $this->blogPostsService->getMatching($filter, BlogPostsModel::FIELD_BLOGPOSTID, Select::ORDER_DESCENDING);
|
||||
$this->assertEquals(blogPostsModel::class, get_class($asc));
|
||||
$this->assertEquals(blogPostsModel::class, get_class($desc));
|
||||
$this->assertNotEquals($asc, $desc);
|
||||
$this->assertEquals($random, $this->blogPostsService->getMatching([BlogPostsModel::FIELD_BLOGPOSTID => $random->getblogPostId()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseBlogPostsService::deleteByField
|
||||
*/
|
||||
public function testDeleteByField()
|
||||
{
|
||||
/** @var BlogPostsModel[] $allDeleted */
|
||||
$allDeleted = [];
|
||||
/** @var BlogPostsModel $deleteable */
|
||||
$deleteable = $this->blogPostsTableGateway
|
||||
->getNewMockModelInstance()
|
||||
->save();
|
||||
$this->assertEquals(1, $this->blogPostsService->deleteByField(BlogPostsModel::FIELD_BLOGPOSTID, $deleteable->getblogPostId()));
|
||||
$allDeleted[] = $deleteable;
|
||||
return $allDeleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testDeleteByField
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseBlogPostsService::deleteByField
|
||||
* @param BlogPostsModel[] $allDeleted
|
||||
*/
|
||||
public function testDeleteByFieldVerify(array $allDeleted)
|
||||
{
|
||||
/** @var BlogPostsModel $deleteable */
|
||||
// By blogPostId
|
||||
$deleteable = array_pop($allDeleted);
|
||||
$this->assertEquals(null, $this->blogPostsService->getByField(BlogPostsModel::FIELD_BLOGPOSTID, $deleteable->getblogPostId()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseBlogPostsService::getTermPlural
|
||||
*/
|
||||
public function testGetTermPlural()
|
||||
{
|
||||
$this->assertNotEmpty($this->blogPostsService->getTermPlural());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseBlogPostsService::getTermSingular
|
||||
*/
|
||||
public function testGetTermSingular()
|
||||
{
|
||||
$this->assertNotEmpty($this->blogPostsService->getTermSingular());
|
||||
}
|
||||
}
|
393
test/app/tests/Services/Generated/MigrationsTest.php
Executable file
393
test/app/tests/Services/Generated/MigrationsTest.php
Executable file
|
@ -0,0 +1,393 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\Test\Services\Generated;
|
||||
|
||||
use Benzine\ORM\Tests\App as App;
|
||||
use Benzine\ORM\Tests\TableGateways\MigrationsTableGateway;
|
||||
use Benzine\ORM\Tests\Services;
|
||||
use Benzine\ORM\Tests\Models\MigrationsModel;
|
||||
use Laminas\Db\Sql\Select;
|
||||
use Laminas\Db\Sql\Where;
|
||||
use Benzine\Tests\BaseTestCase;
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Models\MigrationsModel
|
||||
* @covers \Benzine\ORM\Tests\Models\Base\BaseMigrationsModel
|
||||
* @covers \Benzine\ORM\Tests\Services\MigrationsService
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseMigrationsService
|
||||
* @covers \Benzine\ORM\Tests\TableGateways\MigrationsTableGateway
|
||||
* @covers \Benzine\ORM\Tests\TableGateways\Base\BaseMigrationsTableGateway
|
||||
*
|
||||
* @group generated
|
||||
* @group services
|
||||
* @internal
|
||||
**/
|
||||
class MigrationsTest extends BaseTestCase
|
||||
{
|
||||
protected Services\MigrationsService $migrationsService;
|
||||
protected MigrationsTableGateway $migrationsTableGateway;
|
||||
|
||||
/** @var MigrationsModel[] */
|
||||
private static array $MockData = [];
|
||||
|
||||
/**
|
||||
* @beforeClass
|
||||
*/
|
||||
public static function setupMigrationsMockData(): void
|
||||
{
|
||||
/** @var MigrationsTableGateway $migrationsTableGateway */
|
||||
$migrationsTableGateway = App::DI(MigrationsTableGateway::class);
|
||||
for($i = 0; $i <= 5; $i++){
|
||||
self::$MockData[] = $migrationsTableGateway
|
||||
->getNewMockModelInstance()
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @before
|
||||
*/
|
||||
public function setupMigrationsService(): void
|
||||
{
|
||||
$this->migrationsService = App::DI(Services\MigrationsService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @before
|
||||
*/
|
||||
public function setupMigrationsTableGateway(): void
|
||||
{
|
||||
$this->migrationsTableGateway = App::DI(MigrationsTableGateway::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseMigrationsService::getNewModelInstance
|
||||
*/
|
||||
public function testGetNewModelInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
MigrationsModel::class,
|
||||
$this->migrationsService->getNewModelInstance()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @large
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseMigrationsService::getAll
|
||||
*/
|
||||
public function testGetAll()
|
||||
{
|
||||
$all = $this->migrationsService->getAll();
|
||||
$this->assertInstanceOf(
|
||||
MigrationsModel::class,
|
||||
reset($all)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseMigrationsService::getRandom
|
||||
*/
|
||||
public function testGetRandom()
|
||||
{
|
||||
$random = $this->migrationsService->getRandom();
|
||||
$this->assertInstanceOf(
|
||||
MigrationsModel::class,
|
||||
$random
|
||||
);
|
||||
|
||||
return $random;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseMigrationsService::getByField
|
||||
*/
|
||||
public function testGetByPrimaryKeys(MigrationsModel $random)
|
||||
{
|
||||
/** @var MigrationsModel $found */
|
||||
// By version
|
||||
$found = $this->migrationsService->getByField(MigrationsModel::FIELD_VERSION, $random->getversion());
|
||||
$this->assertInstanceOf(
|
||||
MigrationsModel::class,
|
||||
$found
|
||||
);
|
||||
$this->assertEquals($random, $found);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
*/
|
||||
public function testCreateFromArray(MigrationsModel $random)
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
MigrationsModel::class,
|
||||
$this->migrationsService->createFromArray($random->__toArray())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseMigrationsService::getMockObject
|
||||
*/
|
||||
public function testGetMockObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
MigrationsModel::class,
|
||||
$this->migrationsService->getMockObject()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseMigrationsService::getByField
|
||||
*/
|
||||
public function testGetByField(MigrationsModel $random)
|
||||
{
|
||||
$found = $this->migrationsService->getByField(
|
||||
MigrationsModel::FIELD_VERSION,
|
||||
$random->getVersion()
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
MigrationsModel::class,
|
||||
$found,
|
||||
"Calling Services\\MigrationsService->getByField((MigrationsModel::FIELD_VERSION) failed to find a MigrationsModel"
|
||||
);
|
||||
$found = $this->migrationsService->getByField(
|
||||
MigrationsModel::FIELD_MIGRATION_NAME,
|
||||
$random->getMigration_name()
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
MigrationsModel::class,
|
||||
$found,
|
||||
"Calling Services\\MigrationsService->getByField((MigrationsModel::FIELD_MIGRATION_NAME) failed to find a MigrationsModel"
|
||||
);
|
||||
$found = $this->migrationsService->getByField(
|
||||
MigrationsModel::FIELD_START_TIME,
|
||||
$random->getStart_time()
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
MigrationsModel::class,
|
||||
$found,
|
||||
"Calling Services\\MigrationsService->getByField((MigrationsModel::FIELD_START_TIME) failed to find a MigrationsModel"
|
||||
);
|
||||
$found = $this->migrationsService->getByField(
|
||||
MigrationsModel::FIELD_END_TIME,
|
||||
$random->getEnd_time()
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
MigrationsModel::class,
|
||||
$found,
|
||||
"Calling Services\\MigrationsService->getByField((MigrationsModel::FIELD_END_TIME) failed to find a MigrationsModel"
|
||||
);
|
||||
$found = $this->migrationsService->getByField(
|
||||
MigrationsModel::FIELD_BREAKPOINT,
|
||||
$random->getBreakpoint()
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
MigrationsModel::class,
|
||||
$found,
|
||||
"Calling Services\\MigrationsService->getByField((MigrationsModel::FIELD_BREAKPOINT) failed to find a MigrationsModel"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseMigrationsService::countByField
|
||||
*/
|
||||
public function testCountByField(MigrationsModel $random)
|
||||
{
|
||||
$found = $this->migrationsService->countByField(MigrationsModel::FIELD_VERSION, $random->getVersion());
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
$found,
|
||||
"Calling Services\\MigrationsService->countByField(MigrationsModel::FIELD_VERSION) failed to count a MigrationsModel"
|
||||
);
|
||||
$found = $this->migrationsService->countByField(MigrationsModel::FIELD_MIGRATION_NAME, $random->getMigration_name());
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
$found,
|
||||
"Calling Services\\MigrationsService->countByField(MigrationsModel::FIELD_MIGRATION_NAME) failed to count a MigrationsModel"
|
||||
);
|
||||
$found = $this->migrationsService->countByField(MigrationsModel::FIELD_START_TIME, $random->getStart_time());
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
$found,
|
||||
"Calling Services\\MigrationsService->countByField(MigrationsModel::FIELD_START_TIME) failed to count a MigrationsModel"
|
||||
);
|
||||
$found = $this->migrationsService->countByField(MigrationsModel::FIELD_END_TIME, $random->getEnd_time());
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
$found,
|
||||
"Calling Services\\MigrationsService->countByField(MigrationsModel::FIELD_END_TIME) failed to count a MigrationsModel"
|
||||
);
|
||||
$found = $this->migrationsService->countByField(MigrationsModel::FIELD_BREAKPOINT, $random->getBreakpoint());
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
$found,
|
||||
"Calling Services\\MigrationsService->countByField(MigrationsModel::FIELD_BREAKPOINT) failed to count a MigrationsModel"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseMigrationsService::getManyByField
|
||||
*/
|
||||
public function testGetManyByField(MigrationsModel $random)
|
||||
{
|
||||
// Testing get by version
|
||||
$this->assertContainsOnlyInstancesOf(
|
||||
MigrationsModel::class,
|
||||
$this->migrationsService->getManyByField(
|
||||
MigrationsModel::FIELD_VERSION,
|
||||
$random->getversion(),
|
||||
5
|
||||
)
|
||||
);
|
||||
// Testing get by migration_name
|
||||
$this->assertContainsOnlyInstancesOf(
|
||||
MigrationsModel::class,
|
||||
$this->migrationsService->getManyByField(
|
||||
MigrationsModel::FIELD_MIGRATION_NAME,
|
||||
$random->getmigration_name(),
|
||||
5
|
||||
)
|
||||
);
|
||||
// Testing get by start_time
|
||||
$this->assertContainsOnlyInstancesOf(
|
||||
MigrationsModel::class,
|
||||
$this->migrationsService->getManyByField(
|
||||
MigrationsModel::FIELD_START_TIME,
|
||||
$random->getstart_time(),
|
||||
5
|
||||
)
|
||||
);
|
||||
// Testing get by end_time
|
||||
$this->assertContainsOnlyInstancesOf(
|
||||
MigrationsModel::class,
|
||||
$this->migrationsService->getManyByField(
|
||||
MigrationsModel::FIELD_END_TIME,
|
||||
$random->getend_time(),
|
||||
5
|
||||
)
|
||||
);
|
||||
// Testing get by breakpoint
|
||||
$this->assertContainsOnlyInstancesOf(
|
||||
MigrationsModel::class,
|
||||
$this->migrationsService->getManyByField(
|
||||
MigrationsModel::FIELD_BREAKPOINT,
|
||||
$random->getbreakpoint(),
|
||||
5
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function getMockDataFilter(): \Closure
|
||||
{
|
||||
$mockData = self::$MockData;
|
||||
return function (Where $where) use ($mockData) {
|
||||
$where
|
||||
->nest()
|
||||
->equalTo(MigrationsModel::FIELD_VERSION, $mockData[0]->getversion())
|
||||
->or
|
||||
->equalTo(MigrationsModel::FIELD_VERSION, $mockData[1]->getversion())
|
||||
->or
|
||||
->equalTo(MigrationsModel::FIELD_VERSION, $mockData[2]->getversion())
|
||||
->or
|
||||
->equalTo(MigrationsModel::FIELD_VERSION, $mockData[3]->getversion())
|
||||
->or
|
||||
->equalTo(MigrationsModel::FIELD_VERSION, $mockData[4]->getversion())
|
||||
->or
|
||||
->equalTo(MigrationsModel::FIELD_VERSION, $mockData[5]->getversion())
|
||||
->unnest()
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseMigrationsService::getManyMatching
|
||||
*/
|
||||
public function testGetManyMatching(MigrationsModel $random)
|
||||
{
|
||||
$filter = $this->getMockDataFilter();
|
||||
|
||||
$all = $this->migrationsService->getManyMatching($filter);
|
||||
$this->assertGreaterThan(0, count($all));
|
||||
$this->assertContainsOnlyInstancesOf(MigrationsModel::class, $all);
|
||||
|
||||
$one = $this->migrationsService->getManyMatching($filter, null, Select::ORDER_ASCENDING, 1);
|
||||
$this->assertEquals(1, count($one));
|
||||
$this->assertContainsOnlyInstancesOf(MigrationsModel::class, $one);
|
||||
|
||||
$asc = $this->migrationsService->getMatching($filter, MigrationsModel::FIELD_VERSION, Select::ORDER_ASCENDING);
|
||||
$desc = $this->migrationsService->getMatching($filter, MigrationsModel::FIELD_VERSION, Select::ORDER_DESCENDING);
|
||||
$this->assertEquals(migrationsModel::class, get_class($asc));
|
||||
$this->assertEquals(migrationsModel::class, get_class($desc));
|
||||
$this->assertNotEquals($asc, $desc);
|
||||
$this->assertEquals($random, $this->migrationsService->getMatching([MigrationsModel::FIELD_VERSION => $random->getversion()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseMigrationsService::getMatching
|
||||
*/
|
||||
public function testGetMatching(MigrationsModel $random)
|
||||
{
|
||||
$filter = $this->getMockDataFilter();
|
||||
|
||||
$all = $this->migrationsService->getMatching($filter);
|
||||
$this->assertEquals(migrationsModel::class, get_class($all));
|
||||
|
||||
$asc = $this->migrationsService->getMatching($filter, MigrationsModel::FIELD_VERSION, Select::ORDER_ASCENDING);
|
||||
$desc = $this->migrationsService->getMatching($filter, MigrationsModel::FIELD_VERSION, Select::ORDER_DESCENDING);
|
||||
$this->assertEquals(migrationsModel::class, get_class($asc));
|
||||
$this->assertEquals(migrationsModel::class, get_class($desc));
|
||||
$this->assertNotEquals($asc, $desc);
|
||||
$this->assertEquals($random, $this->migrationsService->getMatching([MigrationsModel::FIELD_VERSION => $random->getversion()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseMigrationsService::deleteByField
|
||||
*/
|
||||
public function testDeleteByField()
|
||||
{
|
||||
/** @var MigrationsModel[] $allDeleted */
|
||||
$allDeleted = [];
|
||||
/** @var MigrationsModel $deleteable */
|
||||
$deleteable = $this->migrationsTableGateway
|
||||
->getNewMockModelInstance()
|
||||
->save();
|
||||
$this->assertEquals(1, $this->migrationsService->deleteByField(MigrationsModel::FIELD_VERSION, $deleteable->getversion()));
|
||||
$allDeleted[] = $deleteable;
|
||||
return $allDeleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testDeleteByField
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseMigrationsService::deleteByField
|
||||
* @param MigrationsModel[] $allDeleted
|
||||
*/
|
||||
public function testDeleteByFieldVerify(array $allDeleted)
|
||||
{
|
||||
/** @var MigrationsModel $deleteable */
|
||||
// By version
|
||||
$deleteable = array_pop($allDeleted);
|
||||
$this->assertEquals(null, $this->migrationsService->getByField(MigrationsModel::FIELD_VERSION, $deleteable->getversion()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseMigrationsService::getTermPlural
|
||||
*/
|
||||
public function testGetTermPlural()
|
||||
{
|
||||
$this->assertNotEmpty($this->migrationsService->getTermPlural());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseMigrationsService::getTermSingular
|
||||
*/
|
||||
public function testGetTermSingular()
|
||||
{
|
||||
$this->assertNotEmpty($this->migrationsService->getTermSingular());
|
||||
}
|
||||
}
|
369
test/app/tests/Services/Generated/UsersTest.php
Executable file
369
test/app/tests/Services/Generated/UsersTest.php
Executable file
|
@ -0,0 +1,369 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\Test\Services\Generated;
|
||||
|
||||
use Benzine\ORM\Tests\App as App;
|
||||
use Benzine\ORM\Tests\TableGateways\UsersTableGateway;
|
||||
use Benzine\ORM\Tests\Services;
|
||||
use Benzine\ORM\Tests\Models\UsersModel;
|
||||
use Laminas\Db\Sql\Select;
|
||||
use Laminas\Db\Sql\Where;
|
||||
use Benzine\Tests\BaseTestCase;
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Models\UsersModel
|
||||
* @covers \Benzine\ORM\Tests\Models\Base\BaseUsersModel
|
||||
* @covers \Benzine\ORM\Tests\Services\UsersService
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseUsersService
|
||||
* @covers \Benzine\ORM\Tests\TableGateways\UsersTableGateway
|
||||
* @covers \Benzine\ORM\Tests\TableGateways\Base\BaseUsersTableGateway
|
||||
*
|
||||
* @group generated
|
||||
* @group services
|
||||
* @internal
|
||||
**/
|
||||
class UsersTest extends BaseTestCase
|
||||
{
|
||||
protected Services\UsersService $usersService;
|
||||
protected UsersTableGateway $usersTableGateway;
|
||||
|
||||
/** @var UsersModel[] */
|
||||
private static array $MockData = [];
|
||||
|
||||
/**
|
||||
* @beforeClass
|
||||
*/
|
||||
public static function setupUsersMockData(): void
|
||||
{
|
||||
/** @var UsersTableGateway $usersTableGateway */
|
||||
$usersTableGateway = App::DI(UsersTableGateway::class);
|
||||
for($i = 0; $i <= 5; $i++){
|
||||
self::$MockData[] = $usersTableGateway
|
||||
->getNewMockModelInstance()
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @before
|
||||
*/
|
||||
public function setupUsersService(): void
|
||||
{
|
||||
$this->usersService = App::DI(Services\UsersService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @before
|
||||
*/
|
||||
public function setupUsersTableGateway(): void
|
||||
{
|
||||
$this->usersTableGateway = App::DI(UsersTableGateway::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseUsersService::getNewModelInstance
|
||||
*/
|
||||
public function testGetNewModelInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
UsersModel::class,
|
||||
$this->usersService->getNewModelInstance()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @large
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseUsersService::getAll
|
||||
*/
|
||||
public function testGetAll()
|
||||
{
|
||||
$all = $this->usersService->getAll();
|
||||
$this->assertInstanceOf(
|
||||
UsersModel::class,
|
||||
reset($all)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseUsersService::getRandom
|
||||
*/
|
||||
public function testGetRandom()
|
||||
{
|
||||
$random = $this->usersService->getRandom();
|
||||
$this->assertInstanceOf(
|
||||
UsersModel::class,
|
||||
$random
|
||||
);
|
||||
|
||||
return $random;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseUsersService::getByField
|
||||
*/
|
||||
public function testGetByPrimaryKeys(UsersModel $random)
|
||||
{
|
||||
/** @var UsersModel $found */
|
||||
// By userId
|
||||
$found = $this->usersService->getByField(UsersModel::FIELD_USERID, $random->getuserId());
|
||||
$this->assertInstanceOf(
|
||||
UsersModel::class,
|
||||
$found
|
||||
);
|
||||
$this->assertEquals($random, $found);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
*/
|
||||
public function testCreateFromArray(UsersModel $random)
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
UsersModel::class,
|
||||
$this->usersService->createFromArray($random->__toArray())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseUsersService::getMockObject
|
||||
*/
|
||||
public function testGetMockObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
UsersModel::class,
|
||||
$this->usersService->getMockObject()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseUsersService::getByField
|
||||
*/
|
||||
public function testGetByField(UsersModel $random)
|
||||
{
|
||||
$found = $this->usersService->getByField(
|
||||
UsersModel::FIELD_USERID,
|
||||
$random->getUserId()
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
UsersModel::class,
|
||||
$found,
|
||||
"Calling Services\\UsersService->getByField((UsersModel::FIELD_USERID) failed to find a UsersModel"
|
||||
);
|
||||
$found = $this->usersService->getByField(
|
||||
UsersModel::FIELD_NAME,
|
||||
$random->getName()
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
UsersModel::class,
|
||||
$found,
|
||||
"Calling Services\\UsersService->getByField((UsersModel::FIELD_NAME) failed to find a UsersModel"
|
||||
);
|
||||
$found = $this->usersService->getByField(
|
||||
UsersModel::FIELD_EMAIL,
|
||||
$random->getEmail()
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
UsersModel::class,
|
||||
$found,
|
||||
"Calling Services\\UsersService->getByField((UsersModel::FIELD_EMAIL) failed to find a UsersModel"
|
||||
);
|
||||
$found = $this->usersService->getByField(
|
||||
UsersModel::FIELD_CREATED,
|
||||
$random->getCreated()
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
UsersModel::class,
|
||||
$found,
|
||||
"Calling Services\\UsersService->getByField((UsersModel::FIELD_CREATED) failed to find a UsersModel"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseUsersService::countByField
|
||||
*/
|
||||
public function testCountByField(UsersModel $random)
|
||||
{
|
||||
$found = $this->usersService->countByField(UsersModel::FIELD_USERID, $random->getUserId());
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
$found,
|
||||
"Calling Services\\UsersService->countByField(UsersModel::FIELD_USERID) failed to count a UsersModel"
|
||||
);
|
||||
$found = $this->usersService->countByField(UsersModel::FIELD_NAME, $random->getName());
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
$found,
|
||||
"Calling Services\\UsersService->countByField(UsersModel::FIELD_NAME) failed to count a UsersModel"
|
||||
);
|
||||
$found = $this->usersService->countByField(UsersModel::FIELD_EMAIL, $random->getEmail());
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
$found,
|
||||
"Calling Services\\UsersService->countByField(UsersModel::FIELD_EMAIL) failed to count a UsersModel"
|
||||
);
|
||||
$found = $this->usersService->countByField(UsersModel::FIELD_CREATED, $random->getCreated());
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
$found,
|
||||
"Calling Services\\UsersService->countByField(UsersModel::FIELD_CREATED) failed to count a UsersModel"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseUsersService::getManyByField
|
||||
*/
|
||||
public function testGetManyByField(UsersModel $random)
|
||||
{
|
||||
// Testing get by userId
|
||||
$this->assertContainsOnlyInstancesOf(
|
||||
UsersModel::class,
|
||||
$this->usersService->getManyByField(
|
||||
UsersModel::FIELD_USERID,
|
||||
$random->getuserId(),
|
||||
5
|
||||
)
|
||||
);
|
||||
// Testing get by name
|
||||
$this->assertContainsOnlyInstancesOf(
|
||||
UsersModel::class,
|
||||
$this->usersService->getManyByField(
|
||||
UsersModel::FIELD_NAME,
|
||||
$random->getname(),
|
||||
5
|
||||
)
|
||||
);
|
||||
// Testing get by email
|
||||
$this->assertContainsOnlyInstancesOf(
|
||||
UsersModel::class,
|
||||
$this->usersService->getManyByField(
|
||||
UsersModel::FIELD_EMAIL,
|
||||
$random->getemail(),
|
||||
5
|
||||
)
|
||||
);
|
||||
// Testing get by created
|
||||
$this->assertContainsOnlyInstancesOf(
|
||||
UsersModel::class,
|
||||
$this->usersService->getManyByField(
|
||||
UsersModel::FIELD_CREATED,
|
||||
$random->getcreated(),
|
||||
5
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function getMockDataFilter(): \Closure
|
||||
{
|
||||
$mockData = self::$MockData;
|
||||
return function (Where $where) use ($mockData) {
|
||||
$where
|
||||
->nest()
|
||||
->equalTo(UsersModel::FIELD_USERID, $mockData[0]->getuserId())
|
||||
->or
|
||||
->equalTo(UsersModel::FIELD_USERID, $mockData[1]->getuserId())
|
||||
->or
|
||||
->equalTo(UsersModel::FIELD_USERID, $mockData[2]->getuserId())
|
||||
->or
|
||||
->equalTo(UsersModel::FIELD_USERID, $mockData[3]->getuserId())
|
||||
->or
|
||||
->equalTo(UsersModel::FIELD_USERID, $mockData[4]->getuserId())
|
||||
->or
|
||||
->equalTo(UsersModel::FIELD_USERID, $mockData[5]->getuserId())
|
||||
->unnest()
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseUsersService::getManyMatching
|
||||
*/
|
||||
public function testGetManyMatching(UsersModel $random)
|
||||
{
|
||||
$filter = $this->getMockDataFilter();
|
||||
|
||||
$all = $this->usersService->getManyMatching($filter);
|
||||
$this->assertGreaterThan(0, count($all));
|
||||
$this->assertContainsOnlyInstancesOf(UsersModel::class, $all);
|
||||
|
||||
$one = $this->usersService->getManyMatching($filter, null, Select::ORDER_ASCENDING, 1);
|
||||
$this->assertEquals(1, count($one));
|
||||
$this->assertContainsOnlyInstancesOf(UsersModel::class, $one);
|
||||
|
||||
$asc = $this->usersService->getMatching($filter, UsersModel::FIELD_USERID, Select::ORDER_ASCENDING);
|
||||
$desc = $this->usersService->getMatching($filter, UsersModel::FIELD_USERID, Select::ORDER_DESCENDING);
|
||||
$this->assertEquals(usersModel::class, get_class($asc));
|
||||
$this->assertEquals(usersModel::class, get_class($desc));
|
||||
$this->assertNotEquals($asc, $desc);
|
||||
$this->assertEquals($random, $this->usersService->getMatching([UsersModel::FIELD_USERID => $random->getuserId()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetRandom
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseUsersService::getMatching
|
||||
*/
|
||||
public function testGetMatching(UsersModel $random)
|
||||
{
|
||||
$filter = $this->getMockDataFilter();
|
||||
|
||||
$all = $this->usersService->getMatching($filter);
|
||||
$this->assertEquals(usersModel::class, get_class($all));
|
||||
|
||||
$asc = $this->usersService->getMatching($filter, UsersModel::FIELD_USERID, Select::ORDER_ASCENDING);
|
||||
$desc = $this->usersService->getMatching($filter, UsersModel::FIELD_USERID, Select::ORDER_DESCENDING);
|
||||
$this->assertEquals(usersModel::class, get_class($asc));
|
||||
$this->assertEquals(usersModel::class, get_class($desc));
|
||||
$this->assertNotEquals($asc, $desc);
|
||||
$this->assertEquals($random, $this->usersService->getMatching([UsersModel::FIELD_USERID => $random->getuserId()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseUsersService::deleteByField
|
||||
*/
|
||||
public function testDeleteByField()
|
||||
{
|
||||
/** @var UsersModel[] $allDeleted */
|
||||
$allDeleted = [];
|
||||
/** @var UsersModel $deleteable */
|
||||
$deleteable = $this->usersTableGateway
|
||||
->getNewMockModelInstance()
|
||||
->save();
|
||||
$this->assertEquals(1, $this->usersService->deleteByField(UsersModel::FIELD_USERID, $deleteable->getuserId()));
|
||||
$allDeleted[] = $deleteable;
|
||||
return $allDeleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testDeleteByField
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseUsersService::deleteByField
|
||||
* @param UsersModel[] $allDeleted
|
||||
*/
|
||||
public function testDeleteByFieldVerify(array $allDeleted)
|
||||
{
|
||||
/** @var UsersModel $deleteable */
|
||||
// By userId
|
||||
$deleteable = array_pop($allDeleted);
|
||||
$this->assertEquals(null, $this->usersService->getByField(UsersModel::FIELD_USERID, $deleteable->getuserId()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseUsersService::getTermPlural
|
||||
*/
|
||||
public function testGetTermPlural()
|
||||
{
|
||||
$this->assertNotEmpty($this->usersService->getTermPlural());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Benzine\ORM\Tests\Services\Base\BaseUsersService::getTermSingular
|
||||
*/
|
||||
public function testGetTermSingular()
|
||||
{
|
||||
$this->assertNotEmpty($this->usersService->getTermSingular());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue