Hack n' slash rework.
This commit is contained in:
parent
d68e3e7a5c
commit
f10bc43335
80 changed files with 87 additions and 5009 deletions
14
bin/laminator
Executable file
14
bin/laminator
Executable file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
use Benzine\App;
|
||||||
|
use Benzine\ORM\Laminator;
|
||||||
|
|
||||||
|
require_once(__DIR__ . "/find-autoloader.php");
|
||||||
|
|
||||||
|
ini_set("memory_limit", "256M");
|
||||||
|
|
||||||
|
App::Instance()
|
||||||
|
->getApp()
|
||||||
|
->getContainer()
|
||||||
|
->get(Laminator::class)
|
||||||
|
->makeLaminator(false);
|
||||||
|
|
@ -18,19 +18,13 @@
|
||||||
"gone.io/twig-extension-transform": "^1.0",
|
"gone.io/twig-extension-transform": "^1.0",
|
||||||
"gone.io/twig-extension-inflection": "^1.0"
|
"gone.io/twig-extension-inflection": "^1.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
|
||||||
"benzine/benzine-style": "dev-master",
|
|
||||||
"benzine/benzine-test": "dev-master"
|
|
||||||
},
|
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"⌬\\Database\\": "src",
|
"Benzine\\ORM\\": "src",
|
||||||
"⌬\\Database\\Tests\\": "tests/"
|
"Benzine\\ORM\\Tests\\": "tests/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bin": [
|
"bin": [
|
||||||
"src/Generator/laminator",
|
"bin/laminator"
|
||||||
"src/Generator/sdkifier",
|
|
||||||
"src/Generator/wait-for-db"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
benzine:
|
|
||||||
application:
|
|
||||||
name: BlogApp
|
|
||||||
namespace: Example\BlogApp
|
|
||||||
logging:
|
|
||||||
format_message: "%level_name% > %message%"
|
|
||||||
migrations:
|
|
||||||
- ./blog.sql
|
|
||||||
databases:
|
|
||||||
mysql:
|
|
||||||
type: mysql
|
|
||||||
host: mysql
|
|
||||||
port: 3306
|
|
||||||
username: root
|
|
||||||
password: ChangeMe
|
|
||||||
database: blog
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
CREATE TABLE `posts`
|
|
||||||
(
|
|
||||||
`id` INT NOT NULL AUTO_INCREMENT,
|
|
||||||
`title` TEXT NOT NULL,
|
|
||||||
`content` TEXT NOT NULL,
|
|
||||||
`authorId` INT NOT NULL,
|
|
||||||
`createdDate` DATETIME NOT NULL,
|
|
||||||
`publishedDate` DATETIME NULL,
|
|
||||||
`deleted` ENUM ('Yes', 'No') NOT NULL DEFAULT 'No',
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE `users`
|
|
||||||
(
|
|
||||||
`id` INT NOT NULL AUTO_INCREMENT,
|
|
||||||
`displayName` VARCHAR(45) NOT NULL,
|
|
||||||
`userName` VARCHAR(45) NOT NULL,
|
|
||||||
`email` VARCHAR(320) NOT NULL,
|
|
||||||
`password` VARCHAR(200) NOT NULL,
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE `comments`
|
|
||||||
(
|
|
||||||
`id` INT NOT NULL AUTO_INCREMENT,
|
|
||||||
`comment` TEXT NOT NULL,
|
|
||||||
`authorId` INT NOT NULL,
|
|
||||||
`publishedDate` DATETIME NOT NULL,
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);
|
|
||||||
|
|
||||||
create index comments_authorId_index
|
|
||||||
on comments (authorId);
|
|
||||||
|
|
||||||
alter table comments
|
|
||||||
add constraint comments_users_id_fk
|
|
||||||
foreign key (authorId) references users (id);
|
|
||||||
|
|
||||||
create index posts_authorId_index
|
|
||||||
on posts (authorId);
|
|
||||||
|
|
||||||
alter table posts
|
|
||||||
add constraint posts_users_id_fk
|
|
||||||
foreign key (authorId) references users (id);
|
|
||||||
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Controllers\Base;
|
|
||||||
|
|
||||||
use Gone\AppCore\Abstracts\CrudController as AbstractCrudController;
|
|
||||||
use \Example\BlogApp\Services;
|
|
||||||
|
|
||||||
/********************************************************
|
|
||||||
* ___ __ *
|
|
||||||
* / _ \___ ____ ___ ____ ____/ / *
|
|
||||||
* / // / _ `/ _ \/ _ `/ -_) __/_/ *
|
|
||||||
* /____/\_,_/_//_/\_, /\__/_/ (_) *
|
|
||||||
* /___/ *
|
|
||||||
* *
|
|
||||||
* Anything in this file is prone to being overwritten! *
|
|
||||||
* *
|
|
||||||
* This file was programatically generated. To modify *
|
|
||||||
* this classes behaviours, do so in the class that *
|
|
||||||
* extends this, or modify the Laminator Template! *
|
|
||||||
********************************************************/
|
|
||||||
abstract class BaseCommentsController extends AbstractCrudController
|
|
||||||
{
|
|
||||||
const RESPONSIBLE_MODEL = 'Comments';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Services\CommentsService $comments
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
Services\CommentsService $comments
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$this->service = $comments;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns Services\CommentsService
|
|
||||||
*/
|
|
||||||
public function getService() : Services\CommentsService
|
|
||||||
{
|
|
||||||
return parent::getService();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Controllers\Base;
|
|
||||||
|
|
||||||
use ⌬\Controllers\Abstracts\CrudController as AbstractCrudController;
|
|
||||||
use \Example\BlogApp\Services;
|
|
||||||
|
|
||||||
/********************************************************
|
|
||||||
* ___ __ *
|
|
||||||
* / _ \___ ____ ___ ____ ____/ / *
|
|
||||||
* / // / _ `/ _ \/ _ `/ -_) __/_/ *
|
|
||||||
* /____/\_,_/_//_/\_, /\__/_/ (_) *
|
|
||||||
* /___/ *
|
|
||||||
* *
|
|
||||||
* Anything in this file is prone to being overwritten! *
|
|
||||||
* *
|
|
||||||
* This file was programatically generated. To modify *
|
|
||||||
* this classes behaviours, do so in the class that *
|
|
||||||
* extends this, or modify the Laminator Template! *
|
|
||||||
********************************************************/
|
|
||||||
abstract class BasePostsController extends AbstractCrudController
|
|
||||||
{
|
|
||||||
const RESPONSIBLE_MODEL = 'Posts';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Services\PostsService $posts
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
Services\PostsService $posts
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$this->service = $posts;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns Services\PostsService
|
|
||||||
*/
|
|
||||||
public function getService() : Services\PostsService
|
|
||||||
{
|
|
||||||
return parent::getService();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Controllers\Base;
|
|
||||||
|
|
||||||
use ⌬\Controllers\Abstracts\CrudController as AbstractCrudController;
|
|
||||||
use \Example\BlogApp\Services;
|
|
||||||
|
|
||||||
/********************************************************
|
|
||||||
* ___ __ *
|
|
||||||
* / _ \___ ____ ___ ____ ____/ / *
|
|
||||||
* / // / _ `/ _ \/ _ `/ -_) __/_/ *
|
|
||||||
* /____/\_,_/_//_/\_, /\__/_/ (_) *
|
|
||||||
* /___/ *
|
|
||||||
* *
|
|
||||||
* Anything in this file is prone to being overwritten! *
|
|
||||||
* *
|
|
||||||
* This file was programatically generated. To modify *
|
|
||||||
* this classes behaviours, do so in the class that *
|
|
||||||
* extends this, or modify the Laminator Template! *
|
|
||||||
********************************************************/
|
|
||||||
abstract class BaseUsersController extends AbstractCrudController
|
|
||||||
{
|
|
||||||
const RESPONSIBLE_MODEL = 'Users';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Services\UsersService $users
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
Services\UsersService $users
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$this->service = $users;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns Services\UsersService
|
|
||||||
*/
|
|
||||||
public function getService() : Services\UsersService
|
|
||||||
{
|
|
||||||
return parent::getService();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Controllers;
|
|
||||||
|
|
||||||
use Example\BlogApp\Controllers\Base\BaseCommentsController;
|
|
||||||
|
|
||||||
class CommentsController extends BaseCommentsController
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Controllers;
|
|
||||||
|
|
||||||
use Example\BlogApp\Controllers\Base\BasePostsController;
|
|
||||||
|
|
||||||
class PostsController extends BasePostsController
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Controllers;
|
|
||||||
|
|
||||||
use Example\BlogApp\Controllers\Base\BaseUsersController;
|
|
||||||
|
|
||||||
class UsersController extends BaseUsersController
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,233 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Models\Base;
|
|
||||||
use \⌬\Config\⌬\⌬ as App;
|
|
||||||
use \Example\BlogApp\Example\BlogApp;
|
|
||||||
use \Gone\AppCore\Exceptions;
|
|
||||||
use \⌬\Controllers\Abstracts\Model as AbstractModel;
|
|
||||||
use ⌬\Database\Interfaces\ModelInterface as ModelInterface;
|
|
||||||
use \Example\BlogApp\Services;
|
|
||||||
use \Example\BlogApp\Models;
|
|
||||||
use \Example\BlogApp\TableGateways;
|
|
||||||
use \Example\BlogApp\Models\CommentsModel;
|
|
||||||
|
|
||||||
/********************************************************
|
|
||||||
* ___ __ *
|
|
||||||
* / _ \___ ____ ___ ____ ____/ / *
|
|
||||||
* / // / _ `/ _ \/ _ `/ -_) __/_/ *
|
|
||||||
* /____/\_,_/_//_/\_, /\__/_/ (_) *
|
|
||||||
* /___/ *
|
|
||||||
* *
|
|
||||||
* Anything in this file is prone to being overwritten! *
|
|
||||||
* *
|
|
||||||
* This file was programatically generated. To modify *
|
|
||||||
* this classes behaviours, do so in the class that *
|
|
||||||
* extends this, or modify the Laminator Template! *
|
|
||||||
********************************************************/
|
|
||||||
abstract class BaseCommentsModel
|
|
||||||
extends AbstractModel
|
|
||||||
implements ModelInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
// Declare what fields are available on this object
|
|
||||||
const FIELD_ID = 'id';
|
|
||||||
const FIELD_COMMENT = 'comment';
|
|
||||||
const FIELD_AUTHORID = 'authorId';
|
|
||||||
const FIELD_PUBLISHEDDATE = 'publishedDate';
|
|
||||||
|
|
||||||
const TYPE_ID = 'int';
|
|
||||||
const TYPE_COMMENT = 'text';
|
|
||||||
const TYPE_AUTHORID = 'int';
|
|
||||||
const TYPE_PUBLISHEDDATE = 'datetime';
|
|
||||||
|
|
||||||
// Constant arrays defined by ENUMs
|
|
||||||
|
|
||||||
// Constants defined by ENUMs
|
|
||||||
|
|
||||||
protected $_primary_keys = ['id'];
|
|
||||||
|
|
||||||
protected $_autoincrement_keys = ['id'];
|
|
||||||
|
|
||||||
protected $id;
|
|
||||||
protected $comment;
|
|
||||||
protected $authorId;
|
|
||||||
protected $publishedDate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data An array of a CommentsModel's properties.
|
|
||||||
* @return CommentsModel
|
|
||||||
*/
|
|
||||||
static public function factory(array $data = [])
|
|
||||||
{
|
|
||||||
return parent::factory($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getPropertyMeta()
|
|
||||||
{
|
|
||||||
$authorsService = App::Container()->get(Services\CommentsService::class);
|
|
||||||
|
|
||||||
$properties = [
|
|
||||||
self::FIELD_ID => [
|
|
||||||
'type' => self::TYPE_ID,
|
|
||||||
'length' => 10,
|
|
||||||
],
|
|
||||||
self::FIELD_COMMENT => [
|
|
||||||
'type' => self::TYPE_COMMENT,
|
|
||||||
'length' => 65535,
|
|
||||||
],
|
|
||||||
self::FIELD_AUTHORID => [
|
|
||||||
'type' => self::TYPE_AUTHORID,
|
|
||||||
'length' => 10,
|
|
||||||
'remoteOptionsLoader' => $authorsService->getAll(),
|
|
||||||
],
|
|
||||||
self::FIELD_PUBLISHEDDATE => [
|
|
||||||
'type' => self::TYPE_PUBLISHEDDATE,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
return $properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getId() : ?int {
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $id
|
|
||||||
* @return CommentsModel
|
|
||||||
*/
|
|
||||||
public function setId(int $id = null) : CommentsModel
|
|
||||||
{
|
|
||||||
$this->id = $id;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getComment() : ?string {
|
|
||||||
return $this->comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $comment
|
|
||||||
* @return CommentsModel
|
|
||||||
*/
|
|
||||||
public function setComment(string $comment = null) : CommentsModel
|
|
||||||
{
|
|
||||||
$this->comment = $comment;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getAuthorId() : ?int {
|
|
||||||
return $this->authorId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $authorId
|
|
||||||
* @return CommentsModel
|
|
||||||
*/
|
|
||||||
public function setAuthorId(int $authorId = null) : CommentsModel
|
|
||||||
{
|
|
||||||
$this->authorId = $authorId;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPublishedDate() : ?string {
|
|
||||||
return $this->publishedDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $publishedDate
|
|
||||||
* @return CommentsModel
|
|
||||||
*/
|
|
||||||
public function setPublishedDate(string $publishedDate = null) : CommentsModel
|
|
||||||
{
|
|
||||||
$this->publishedDate = $publishedDate;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************
|
|
||||||
* "Referenced To" Remote Constraint Object Fetchers *
|
|
||||||
*****************************************************/
|
|
||||||
/**
|
|
||||||
* @return null|Models\UsersModel
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function fetchUserObject() : ?Models\UsersModel
|
|
||||||
{
|
|
||||||
/** @var $UsersService Services\UsersService */
|
|
||||||
$UsersService = App::Container()->get(Services\UsersService::class);
|
|
||||||
return $UsersService->getById($this->getAuthorId());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return CommentsModel
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function save()
|
|
||||||
{
|
|
||||||
/** @var $tableGateway TableGateways\CommentsTableGateway */
|
|
||||||
$tableGateway = App::Container()->get(TableGateways\CommentsTableGateway::class);
|
|
||||||
return $tableGateway->save($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroy the current record.
|
|
||||||
*
|
|
||||||
* @return int Number of affected rows.
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function destroy() : int
|
|
||||||
{
|
|
||||||
/** @var $tableGateway TableGateways\CommentsTableGateway */
|
|
||||||
$tableGateway = App::Container()->get(TableGateways\CommentsTableGateway::class);
|
|
||||||
return $tableGateway->delete($this->getPrimaryKeys());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroy the current record, and any dependencies upon it, recursively.
|
|
||||||
*
|
|
||||||
* @return int Number of affected models.
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function destroyThoroughly() : int
|
|
||||||
{
|
|
||||||
return $this->destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides an array of all properties in this model.
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getListOfProperties()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'id',
|
|
||||||
'comment',
|
|
||||||
'authorId',
|
|
||||||
'publishedDate',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,315 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Models\Base;
|
|
||||||
use \⌬\Config\⌬\⌬ as App;
|
|
||||||
use \Example\BlogApp\Example\BlogApp;
|
|
||||||
use \Gone\AppCore\Exceptions;
|
|
||||||
use \⌬\Controllers\Abstracts\Model as AbstractModel;
|
|
||||||
use ⌬\Database\Interfaces\ModelInterface as ModelInterface;
|
|
||||||
use \Example\BlogApp\Services;
|
|
||||||
use \Example\BlogApp\Models;
|
|
||||||
use \Example\BlogApp\TableGateways;
|
|
||||||
use \Example\BlogApp\Models\PostsModel;
|
|
||||||
|
|
||||||
/********************************************************
|
|
||||||
* ___ __ *
|
|
||||||
* / _ \___ ____ ___ ____ ____/ / *
|
|
||||||
* / // / _ `/ _ \/ _ `/ -_) __/_/ *
|
|
||||||
* /____/\_,_/_//_/\_, /\__/_/ (_) *
|
|
||||||
* /___/ *
|
|
||||||
* *
|
|
||||||
* Anything in this file is prone to being overwritten! *
|
|
||||||
* *
|
|
||||||
* This file was programatically generated. To modify *
|
|
||||||
* this classes behaviours, do so in the class that *
|
|
||||||
* extends this, or modify the Laminator Template! *
|
|
||||||
********************************************************/
|
|
||||||
abstract class BasePostsModel
|
|
||||||
extends AbstractModel
|
|
||||||
implements ModelInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
// Declare what fields are available on this object
|
|
||||||
const FIELD_ID = 'id';
|
|
||||||
const FIELD_TITLE = 'title';
|
|
||||||
const FIELD_CONTENT = 'content';
|
|
||||||
const FIELD_AUTHORID = 'authorId';
|
|
||||||
const FIELD_CREATEDDATE = 'createdDate';
|
|
||||||
const FIELD_PUBLISHEDDATE = 'publishedDate';
|
|
||||||
const FIELD_DELETED = 'deleted';
|
|
||||||
|
|
||||||
const TYPE_ID = 'int';
|
|
||||||
const TYPE_TITLE = 'text';
|
|
||||||
const TYPE_CONTENT = 'text';
|
|
||||||
const TYPE_AUTHORID = 'int';
|
|
||||||
const TYPE_CREATEDDATE = 'datetime';
|
|
||||||
const TYPE_PUBLISHEDDATE = 'datetime';
|
|
||||||
const TYPE_DELETED = 'enum';
|
|
||||||
|
|
||||||
// Constant arrays defined by ENUMs
|
|
||||||
const OPTIONS_DELETED = ["Yes", "No"];
|
|
||||||
|
|
||||||
// Constants defined by ENUMs
|
|
||||||
const DELETED_YES = 'Yes';
|
|
||||||
const DELETED_NO = 'No';
|
|
||||||
|
|
||||||
protected $_primary_keys = ['id'];
|
|
||||||
|
|
||||||
protected $_autoincrement_keys = ['id'];
|
|
||||||
|
|
||||||
protected $id;
|
|
||||||
protected $title;
|
|
||||||
protected $content;
|
|
||||||
protected $authorId;
|
|
||||||
protected $createdDate;
|
|
||||||
protected $publishedDate;
|
|
||||||
protected $deleted;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data An array of a PostsModel's properties.
|
|
||||||
* @return PostsModel
|
|
||||||
*/
|
|
||||||
static public function factory(array $data = [])
|
|
||||||
{
|
|
||||||
return parent::factory($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getPropertyMeta()
|
|
||||||
{
|
|
||||||
$authorsService = App::Container()->get(Services\PostsService::class);
|
|
||||||
|
|
||||||
$properties = [
|
|
||||||
self::FIELD_ID => [
|
|
||||||
'type' => self::TYPE_ID,
|
|
||||||
'length' => 10,
|
|
||||||
],
|
|
||||||
self::FIELD_TITLE => [
|
|
||||||
'type' => self::TYPE_TITLE,
|
|
||||||
'length' => 65535,
|
|
||||||
],
|
|
||||||
self::FIELD_CONTENT => [
|
|
||||||
'type' => self::TYPE_CONTENT,
|
|
||||||
'length' => 65535,
|
|
||||||
],
|
|
||||||
self::FIELD_AUTHORID => [
|
|
||||||
'type' => self::TYPE_AUTHORID,
|
|
||||||
'length' => 10,
|
|
||||||
'remoteOptionsLoader' => $authorsService->getAll(),
|
|
||||||
],
|
|
||||||
self::FIELD_CREATEDDATE => [
|
|
||||||
'type' => self::TYPE_CREATEDDATE,
|
|
||||||
],
|
|
||||||
self::FIELD_PUBLISHEDDATE => [
|
|
||||||
'type' => self::TYPE_PUBLISHEDDATE,
|
|
||||||
],
|
|
||||||
self::FIELD_DELETED => [
|
|
||||||
'type' => self::TYPE_DELETED,
|
|
||||||
'length' => 3,
|
|
||||||
'options' => [
|
|
||||||
'Yes',
|
|
||||||
'No',
|
|
||||||
],
|
|
||||||
'default' => ''No'',
|
|
||||||
],
|
|
||||||
];
|
|
||||||
return $properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getId() : ?int {
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $id
|
|
||||||
* @return PostsModel
|
|
||||||
*/
|
|
||||||
public function setId(int $id = null) : PostsModel
|
|
||||||
{
|
|
||||||
$this->id = $id;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getTitle() : ?string {
|
|
||||||
return $this->title;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $title
|
|
||||||
* @return PostsModel
|
|
||||||
*/
|
|
||||||
public function setTitle(string $title = null) : PostsModel
|
|
||||||
{
|
|
||||||
$this->title = $title;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getContent() : ?string {
|
|
||||||
return $this->content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $content
|
|
||||||
* @return PostsModel
|
|
||||||
*/
|
|
||||||
public function setContent(string $content = null) : PostsModel
|
|
||||||
{
|
|
||||||
$this->content = $content;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getAuthorId() : ?int {
|
|
||||||
return $this->authorId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $authorId
|
|
||||||
* @return PostsModel
|
|
||||||
*/
|
|
||||||
public function setAuthorId(int $authorId = null) : PostsModel
|
|
||||||
{
|
|
||||||
$this->authorId = $authorId;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getCreatedDate() : ?string {
|
|
||||||
return $this->createdDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $createdDate
|
|
||||||
* @return PostsModel
|
|
||||||
*/
|
|
||||||
public function setCreatedDate(string $createdDate = null) : PostsModel
|
|
||||||
{
|
|
||||||
$this->createdDate = $createdDate;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPublishedDate() : ?string {
|
|
||||||
return $this->publishedDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $publishedDate
|
|
||||||
* @return PostsModel
|
|
||||||
*/
|
|
||||||
public function setPublishedDate(string $publishedDate = null) : PostsModel
|
|
||||||
{
|
|
||||||
$this->publishedDate = $publishedDate;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getDeleted() : ?string {
|
|
||||||
return $this->deleted;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $deleted
|
|
||||||
* @return PostsModel
|
|
||||||
*/
|
|
||||||
public function setDeleted(string $deleted = null) : PostsModel
|
|
||||||
{
|
|
||||||
$this->deleted = $deleted;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************
|
|
||||||
* "Referenced To" Remote Constraint Object Fetchers *
|
|
||||||
*****************************************************/
|
|
||||||
/**
|
|
||||||
* @return null|Models\UsersModel
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function fetchUserObject() : ?Models\UsersModel
|
|
||||||
{
|
|
||||||
/** @var $UsersService Services\UsersService */
|
|
||||||
$UsersService = App::Container()->get(Services\UsersService::class);
|
|
||||||
return $UsersService->getById($this->getAuthorId());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return PostsModel
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function save()
|
|
||||||
{
|
|
||||||
/** @var $tableGateway TableGateways\PostsTableGateway */
|
|
||||||
$tableGateway = App::Container()->get(TableGateways\PostsTableGateway::class);
|
|
||||||
return $tableGateway->save($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroy the current record.
|
|
||||||
*
|
|
||||||
* @return int Number of affected rows.
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function destroy() : int
|
|
||||||
{
|
|
||||||
/** @var $tableGateway TableGateways\PostsTableGateway */
|
|
||||||
$tableGateway = App::Container()->get(TableGateways\PostsTableGateway::class);
|
|
||||||
return $tableGateway->delete($this->getPrimaryKeys());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroy the current record, and any dependencies upon it, recursively.
|
|
||||||
*
|
|
||||||
* @return int Number of affected models.
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function destroyThoroughly() : int
|
|
||||||
{
|
|
||||||
return $this->destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides an array of all properties in this model.
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getListOfProperties()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'id',
|
|
||||||
'title',
|
|
||||||
'content',
|
|
||||||
'authorId',
|
|
||||||
'createdDate',
|
|
||||||
'publishedDate',
|
|
||||||
'deleted',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,359 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Models\Base;
|
|
||||||
use \⌬\Config\⌬\⌬ as App;
|
|
||||||
use \Example\BlogApp\Example\BlogApp;
|
|
||||||
use \Gone\AppCore\Exceptions;
|
|
||||||
use \⌬\Controllers\Abstracts\Model as AbstractModel;
|
|
||||||
use ⌬\Database\Interfaces\ModelInterface as ModelInterface;
|
|
||||||
use \Example\BlogApp\Services;
|
|
||||||
use \Example\BlogApp\Models;
|
|
||||||
use \Example\BlogApp\TableGateways;
|
|
||||||
use \Example\BlogApp\Models\UsersModel;
|
|
||||||
|
|
||||||
/********************************************************
|
|
||||||
* ___ __ *
|
|
||||||
* / _ \___ ____ ___ ____ ____/ / *
|
|
||||||
* / // / _ `/ _ \/ _ `/ -_) __/_/ *
|
|
||||||
* /____/\_,_/_//_/\_, /\__/_/ (_) *
|
|
||||||
* /___/ *
|
|
||||||
* *
|
|
||||||
* Anything in this file is prone to being overwritten! *
|
|
||||||
* *
|
|
||||||
* This file was programatically 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
|
|
||||||
const FIELD_ID = 'id';
|
|
||||||
const FIELD_DISPLAYNAME = 'displayName';
|
|
||||||
const FIELD_USERNAME = 'userName';
|
|
||||||
const FIELD_EMAIL = 'email';
|
|
||||||
const FIELD_PASSWORD = 'password';
|
|
||||||
|
|
||||||
const TYPE_ID = 'int';
|
|
||||||
const TYPE_DISPLAYNAME = 'varchar';
|
|
||||||
const TYPE_USERNAME = 'varchar';
|
|
||||||
const TYPE_EMAIL = 'varchar';
|
|
||||||
const TYPE_PASSWORD = 'varchar';
|
|
||||||
|
|
||||||
// Constant arrays defined by ENUMs
|
|
||||||
|
|
||||||
// Constants defined by ENUMs
|
|
||||||
|
|
||||||
protected $_primary_keys = ['id'];
|
|
||||||
|
|
||||||
protected $_autoincrement_keys = ['id'];
|
|
||||||
|
|
||||||
protected $id;
|
|
||||||
protected $displayName;
|
|
||||||
protected $userName;
|
|
||||||
protected $email;
|
|
||||||
protected $password;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data An array of a UsersModel's properties.
|
|
||||||
* @return UsersModel
|
|
||||||
*/
|
|
||||||
static public function factory(array $data = [])
|
|
||||||
{
|
|
||||||
return parent::factory($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getPropertyMeta()
|
|
||||||
{
|
|
||||||
|
|
||||||
$properties = [
|
|
||||||
self::FIELD_ID => [
|
|
||||||
'type' => self::TYPE_ID,
|
|
||||||
'length' => 10,
|
|
||||||
],
|
|
||||||
self::FIELD_DISPLAYNAME => [
|
|
||||||
'type' => self::TYPE_DISPLAYNAME,
|
|
||||||
'length' => 45,
|
|
||||||
],
|
|
||||||
self::FIELD_USERNAME => [
|
|
||||||
'type' => self::TYPE_USERNAME,
|
|
||||||
'length' => 45,
|
|
||||||
],
|
|
||||||
self::FIELD_EMAIL => [
|
|
||||||
'type' => self::TYPE_EMAIL,
|
|
||||||
'length' => 320,
|
|
||||||
],
|
|
||||||
self::FIELD_PASSWORD => [
|
|
||||||
'type' => self::TYPE_PASSWORD,
|
|
||||||
'length' => 200,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
return $properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getId() : ?int {
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $id
|
|
||||||
* @return UsersModel
|
|
||||||
*/
|
|
||||||
public function setId(int $id = null) : UsersModel
|
|
||||||
{
|
|
||||||
$this->id = $id;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getDisplayName() : ?string {
|
|
||||||
return $this->displayName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $displayName
|
|
||||||
* @return UsersModel
|
|
||||||
*/
|
|
||||||
public function setDisplayName(string $displayName = null) : UsersModel
|
|
||||||
{
|
|
||||||
$this->displayName = $displayName;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getUserName() : ?string {
|
|
||||||
return $this->userName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $userName
|
|
||||||
* @return UsersModel
|
|
||||||
*/
|
|
||||||
public function setUserName(string $userName = null) : UsersModel
|
|
||||||
{
|
|
||||||
$this->userName = $userName;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getEmail() : ?string {
|
|
||||||
return $this->email;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $email
|
|
||||||
* @return UsersModel
|
|
||||||
*/
|
|
||||||
public function setEmail(string $email = null) : UsersModel
|
|
||||||
{
|
|
||||||
$this->email = $email;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPassword() : ?string {
|
|
||||||
return $this->password;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $password
|
|
||||||
* @return UsersModel
|
|
||||||
*/
|
|
||||||
public function setPassword(string $password = null) : UsersModel
|
|
||||||
{
|
|
||||||
$this->password = $password;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************
|
|
||||||
* "Referenced To" Remote Constraint Object Fetchers *
|
|
||||||
*****************************************************/
|
|
||||||
/*****************************************************
|
|
||||||
* "Referenced By" Remote Constraint Object Fetchers *
|
|
||||||
*****************************************************/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch a singular Post that references this UsersModel.
|
|
||||||
*
|
|
||||||
* @param $orderBy string Column to order by. Recommended to use the Constants in Models\PostsModel::
|
|
||||||
* @param $orderDirection string Either "DESC" or "ASC". Recommend using Select::ORDER_ASCENDING or Select::ORDER_DESCENDING
|
|
||||||
*
|
|
||||||
* @return null|Models\PostsModel
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function fetchPostObject(
|
|
||||||
$orderBy = null,
|
|
||||||
$orderDirection='ASC'
|
|
||||||
) : ?Models\PostsModel {
|
|
||||||
/** @var $postsService Services\PostsService */
|
|
||||||
$postsService = App::Container()->get(Services\PostsService::class);
|
|
||||||
return $postsService->getByField('authorId', $this->getId(), $orderBy, $orderDirection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch all matching Post that reference this UsersModel.
|
|
||||||
*
|
|
||||||
* @param $limit int Number to fetch maximum
|
|
||||||
* @param $orderBy string Column to order by. Recommended to use the Constants in Models\PostsModel::
|
|
||||||
* @param $orderDirection string Either "DESC" or "ASC". Recommend using Select::ORDER_ASCENDING or Select::ORDER_DESCENDING
|
|
||||||
*
|
|
||||||
* @return Models\PostsModel[]
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function fetchPostObjects(
|
|
||||||
int $limit = null,
|
|
||||||
string $orderBy = null,
|
|
||||||
string $orderDirection='ASC'
|
|
||||||
) : ?array {
|
|
||||||
/** @var $postsService Services\PostsService */
|
|
||||||
$postsService = App::Container()->get(Services\PostsService::class);
|
|
||||||
return $postsService->getManyByField('authorId', $this->getId(), $limit, $orderBy, $orderDirection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Count the number of matching Post that reference this UsersModel.
|
|
||||||
*
|
|
||||||
* @return int Number of objects found.
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function countPostObjects() : int {
|
|
||||||
/** @var $postsService Services\PostsService */
|
|
||||||
$postsService = App::Container()->get(Services\PostsService::class);
|
|
||||||
return $postsService->countByField('authorId', $this->getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch a singular Comment that references this UsersModel.
|
|
||||||
*
|
|
||||||
* @param $orderBy string Column to order by. Recommended to use the Constants in Models\CommentsModel::
|
|
||||||
* @param $orderDirection string Either "DESC" or "ASC". Recommend using Select::ORDER_ASCENDING or Select::ORDER_DESCENDING
|
|
||||||
*
|
|
||||||
* @return null|Models\CommentsModel
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function fetchCommentObject(
|
|
||||||
$orderBy = null,
|
|
||||||
$orderDirection='ASC'
|
|
||||||
) : ?Models\CommentsModel {
|
|
||||||
/** @var $commentsService Services\CommentsService */
|
|
||||||
$commentsService = App::Container()->get(Services\CommentsService::class);
|
|
||||||
return $commentsService->getByField('authorId', $this->getId(), $orderBy, $orderDirection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch all matching Comment that reference this UsersModel.
|
|
||||||
*
|
|
||||||
* @param $limit int Number to fetch maximum
|
|
||||||
* @param $orderBy string Column to order by. Recommended to use the Constants in Models\CommentsModel::
|
|
||||||
* @param $orderDirection string Either "DESC" or "ASC". Recommend using Select::ORDER_ASCENDING or Select::ORDER_DESCENDING
|
|
||||||
*
|
|
||||||
* @return Models\CommentsModel[]
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function fetchCommentObjects(
|
|
||||||
int $limit = null,
|
|
||||||
string $orderBy = null,
|
|
||||||
string $orderDirection='ASC'
|
|
||||||
) : ?array {
|
|
||||||
/** @var $commentsService Services\CommentsService */
|
|
||||||
$commentsService = App::Container()->get(Services\CommentsService::class);
|
|
||||||
return $commentsService->getManyByField('authorId', $this->getId(), $limit, $orderBy, $orderDirection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Count the number of matching Comment that reference this UsersModel.
|
|
||||||
*
|
|
||||||
* @return int Number of objects found.
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function countCommentObjects() : int {
|
|
||||||
/** @var $commentsService Services\CommentsService */
|
|
||||||
$commentsService = App::Container()->get(Services\CommentsService::class);
|
|
||||||
return $commentsService->countByField('authorId', $this->getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return UsersModel
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function save()
|
|
||||||
{
|
|
||||||
/** @var $tableGateway TableGateways\UsersTableGateway */
|
|
||||||
$tableGateway = App::Container()->get(TableGateways\UsersTableGateway::class);
|
|
||||||
return $tableGateway->save($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroy the current record.
|
|
||||||
*
|
|
||||||
* @return int Number of affected rows.
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function destroy() : int
|
|
||||||
{
|
|
||||||
/** @var $tableGateway TableGateways\UsersTableGateway */
|
|
||||||
$tableGateway = App::Container()->get(TableGateways\UsersTableGateway::class);
|
|
||||||
return $tableGateway->delete($this->getPrimaryKeys());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroy the current record, and any dependencies upon it, recursively.
|
|
||||||
*
|
|
||||||
* @return int Number of affected models.
|
|
||||||
*
|
|
||||||
* @throws \Psr\Container\ContainerExceptionInterface
|
|
||||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
public function destroyThoroughly() : int
|
|
||||||
{
|
|
||||||
return $this->destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides an array of all properties in this model.
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getListOfProperties()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'id',
|
|
||||||
'displayName',
|
|
||||||
'userName',
|
|
||||||
'email',
|
|
||||||
'password',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Models;
|
|
||||||
use Example\BlogApp\Models\Base\BaseCommentsModel;
|
|
||||||
|
|
||||||
class CommentsModel extends BaseCommentsModel
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Models;
|
|
||||||
use Example\BlogApp\Models\Base\BasePostsModel;
|
|
||||||
|
|
||||||
class PostsModel extends BasePostsModel
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Models;
|
|
||||||
use Example\BlogApp\Models\Base\BaseUsersModel;
|
|
||||||
|
|
||||||
class UsersModel extends BaseUsersModel
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,107 +0,0 @@
|
||||||
<?php
|
|
||||||
$exampleExistingObjectFindFunction = function()
|
|
||||||
{
|
|
||||||
$DIContainer = \⌬\Config\⌬\⌬::Instance()->getContainer();
|
|
||||||
$tableGateway = $DIContainer->get(\Example\BlogApp\TableGateways\CommentsTableGateway::class);
|
|
||||||
|
|
||||||
/** @var \Example\BlogApp\TableGateways\CommentsTableGateway $exampleExistingObjectTableGateway */
|
|
||||||
$exampleExistingObjectTableGateway = $DIContainer->get(\Example\BlogApp\TableGateways\CommentsTableGateway::class);
|
|
||||||
|
|
||||||
/** @var \Example\BlogApp\Models\CommentsModel $exampleExistingObject */
|
|
||||||
$exampleExistingObject = $exampleExistingObjectTableGateway->getNewMockModelInstance();
|
|
||||||
if(method_exists($exampleExistingObject, 'setId')){
|
|
||||||
$exampleExistingObject->setId(rand(1000000,9999999));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $exampleExistingObject;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Router proper begins
|
|
||||||
$router = \⌬\Router\Router::Instance()
|
|
||||||
->addRoute(
|
|
||||||
\⌬\Router\Route::Factory()
|
|
||||||
->setName('Comments List')
|
|
||||||
->setCallback(\Example\BlogApp\Controllers\CommentsController::class . ':listRequest')
|
|
||||||
->setSDKClass('Comments')
|
|
||||||
->setSDKFunction('list')
|
|
||||||
->setSDKTemplate('list')
|
|
||||||
->setRouterPattern('/v1/comments')
|
|
||||||
->setHttpEndpoint( '/v1/comments')
|
|
||||||
->setHttpMethod('GET')
|
|
||||||
->setSingular('Comments')
|
|
||||||
->setPlural('Comments')
|
|
||||||
->setProperties([
|
|
||||||
'Id',
|
|
||||||
'Comment',
|
|
||||||
'AuthorId',
|
|
||||||
'PublishedDate',
|
|
||||||
])
|
|
||||||
->setPropertyOptions([
|
|
||||||
])
|
|
||||||
->setAccess(DEFAULT_ROUTE_ACCESS_MODE)
|
|
||||||
->setExampleEntityFindFunction($exampleExistingObjectFindFunction)
|
|
||||||
)
|
|
||||||
->addRoute(
|
|
||||||
\⌬\Router\Route::Factory()
|
|
||||||
->setName('Comments Create')
|
|
||||||
->setCallback(\Example\BlogApp\Controllers\CommentsController::class . ':createRequest')
|
|
||||||
->setSDKClass('Comments')
|
|
||||||
->setSDKFunction('create')
|
|
||||||
->setSDKTemplate('create')
|
|
||||||
->setRouterPattern('/v1/comments')
|
|
||||||
->setHttpEndpoint( '/v1/comments')
|
|
||||||
->setHttpMethod('PUT')
|
|
||||||
->setSingular('Comments')
|
|
||||||
->setPlural('Comments')
|
|
||||||
->setProperties([
|
|
||||||
'Id',
|
|
||||||
'Comment',
|
|
||||||
'AuthorId',
|
|
||||||
'PublishedDate',
|
|
||||||
])
|
|
||||||
->setAccess(DEFAULT_ROUTE_ACCESS_MODE)
|
|
||||||
->setExampleEntityFindFunction($exampleExistingObjectFindFunction)
|
|
||||||
)
|
|
||||||
->addRoute(
|
|
||||||
\⌬\Router\Route::Factory()
|
|
||||||
->setName('Comments Get')
|
|
||||||
->setCallback(\Example\BlogApp\Controllers\CommentsController::class . ':getRequest')
|
|
||||||
->setSDKClass('Comments')
|
|
||||||
->setSDKFunction('get')
|
|
||||||
->setSDKTemplate('get')
|
|
||||||
->setRouterPattern('/v1/comments/{id}')
|
|
||||||
->setHttpEndpoint( '/v1/comments/id')
|
|
||||||
->setHttpMethod('GET')
|
|
||||||
->setSingular('Comments')
|
|
||||||
->setPlural('Comments')
|
|
||||||
->setProperties([
|
|
||||||
'Id',
|
|
||||||
'Comment',
|
|
||||||
'AuthorId',
|
|
||||||
'PublishedDate',
|
|
||||||
])
|
|
||||||
->setAccess(DEFAULT_ROUTE_ACCESS_MODE)
|
|
||||||
->setExampleEntityFindFunction($exampleExistingObjectFindFunction)
|
|
||||||
)
|
|
||||||
->addRoute(
|
|
||||||
\⌬\Router\Route::Factory()
|
|
||||||
->setName('Comments Delete')
|
|
||||||
->setCallback(\Example\BlogApp\Controllers\CommentsController::class . ':deleteRequest')
|
|
||||||
->setSDKClass('Comments')
|
|
||||||
->setSDKFunction('delete')
|
|
||||||
->setSDKTemplate('delete')
|
|
||||||
->setRouterPattern('/v1/comments/{id}')
|
|
||||||
->setHttpEndpoint( '/v1/comments/id')
|
|
||||||
->setHttpMethod('DELETE')
|
|
||||||
->setSingular('Comments')
|
|
||||||
->setPlural('Comments')
|
|
||||||
->setProperties([
|
|
||||||
'Id',
|
|
||||||
'Comment',
|
|
||||||
'AuthorId',
|
|
||||||
'PublishedDate',
|
|
||||||
])
|
|
||||||
->setAccess(DEFAULT_ROUTE_ACCESS_MODE)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,123 +0,0 @@
|
||||||
<?php
|
|
||||||
$exampleExistingObjectFindFunction = function()
|
|
||||||
{
|
|
||||||
$DIContainer = \⌬\Config\⌬\⌬::Instance()->getContainer();
|
|
||||||
$tableGateway = $DIContainer->get(\Example\BlogApp\TableGateways\PostsTableGateway::class);
|
|
||||||
|
|
||||||
/** @var \Example\BlogApp\TableGateways\PostsTableGateway $exampleExistingObjectTableGateway */
|
|
||||||
$exampleExistingObjectTableGateway = $DIContainer->get(\Example\BlogApp\TableGateways\PostsTableGateway::class);
|
|
||||||
|
|
||||||
/** @var \Example\BlogApp\Models\PostsModel $exampleExistingObject */
|
|
||||||
$exampleExistingObject = $exampleExistingObjectTableGateway->getNewMockModelInstance();
|
|
||||||
if(method_exists($exampleExistingObject, 'setId')){
|
|
||||||
$exampleExistingObject->setId(rand(1000000,9999999));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $exampleExistingObject;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Router proper begins
|
|
||||||
$router = \⌬\Router\Router::Instance()
|
|
||||||
->addRoute(
|
|
||||||
\⌬\Router\Route::Factory()
|
|
||||||
->setName('Posts List')
|
|
||||||
->setCallback(\Example\BlogApp\Controllers\PostsController::class . ':listRequest')
|
|
||||||
->setSDKClass('Posts')
|
|
||||||
->setSDKFunction('list')
|
|
||||||
->setSDKTemplate('list')
|
|
||||||
->setRouterPattern('/v1/posts')
|
|
||||||
->setHttpEndpoint( '/v1/posts')
|
|
||||||
->setHttpMethod('GET')
|
|
||||||
->setSingular('Posts')
|
|
||||||
->setPlural('Posts')
|
|
||||||
->setProperties([
|
|
||||||
'Id',
|
|
||||||
'Title',
|
|
||||||
'Content',
|
|
||||||
'AuthorId',
|
|
||||||
'CreatedDate',
|
|
||||||
'PublishedDate',
|
|
||||||
'Deleted',
|
|
||||||
])
|
|
||||||
->setPropertyOptions([
|
|
||||||
'Deleted' => [
|
|
||||||
"Yes",
|
|
||||||
"No",
|
|
||||||
],
|
|
||||||
])
|
|
||||||
->setAccess(DEFAULT_ROUTE_ACCESS_MODE)
|
|
||||||
->setExampleEntityFindFunction($exampleExistingObjectFindFunction)
|
|
||||||
)
|
|
||||||
->addRoute(
|
|
||||||
\⌬\Router\Route::Factory()
|
|
||||||
->setName('Posts Create')
|
|
||||||
->setCallback(\Example\BlogApp\Controllers\PostsController::class . ':createRequest')
|
|
||||||
->setSDKClass('Posts')
|
|
||||||
->setSDKFunction('create')
|
|
||||||
->setSDKTemplate('create')
|
|
||||||
->setRouterPattern('/v1/posts')
|
|
||||||
->setHttpEndpoint( '/v1/posts')
|
|
||||||
->setHttpMethod('PUT')
|
|
||||||
->setSingular('Posts')
|
|
||||||
->setPlural('Posts')
|
|
||||||
->setProperties([
|
|
||||||
'Id',
|
|
||||||
'Title',
|
|
||||||
'Content',
|
|
||||||
'AuthorId',
|
|
||||||
'CreatedDate',
|
|
||||||
'PublishedDate',
|
|
||||||
'Deleted',
|
|
||||||
])
|
|
||||||
->setAccess(DEFAULT_ROUTE_ACCESS_MODE)
|
|
||||||
->setExampleEntityFindFunction($exampleExistingObjectFindFunction)
|
|
||||||
)
|
|
||||||
->addRoute(
|
|
||||||
\⌬\Router\Route::Factory()
|
|
||||||
->setName('Posts Get')
|
|
||||||
->setCallback(\Example\BlogApp\Controllers\PostsController::class . ':getRequest')
|
|
||||||
->setSDKClass('Posts')
|
|
||||||
->setSDKFunction('get')
|
|
||||||
->setSDKTemplate('get')
|
|
||||||
->setRouterPattern('/v1/posts/{id}')
|
|
||||||
->setHttpEndpoint( '/v1/posts/id')
|
|
||||||
->setHttpMethod('GET')
|
|
||||||
->setSingular('Posts')
|
|
||||||
->setPlural('Posts')
|
|
||||||
->setProperties([
|
|
||||||
'Id',
|
|
||||||
'Title',
|
|
||||||
'Content',
|
|
||||||
'AuthorId',
|
|
||||||
'CreatedDate',
|
|
||||||
'PublishedDate',
|
|
||||||
'Deleted',
|
|
||||||
])
|
|
||||||
->setAccess(DEFAULT_ROUTE_ACCESS_MODE)
|
|
||||||
->setExampleEntityFindFunction($exampleExistingObjectFindFunction)
|
|
||||||
)
|
|
||||||
->addRoute(
|
|
||||||
\⌬\Router\Route::Factory()
|
|
||||||
->setName('Posts Delete')
|
|
||||||
->setCallback(\Example\BlogApp\Controllers\PostsController::class . ':deleteRequest')
|
|
||||||
->setSDKClass('Posts')
|
|
||||||
->setSDKFunction('delete')
|
|
||||||
->setSDKTemplate('delete')
|
|
||||||
->setRouterPattern('/v1/posts/{id}')
|
|
||||||
->setHttpEndpoint( '/v1/posts/id')
|
|
||||||
->setHttpMethod('DELETE')
|
|
||||||
->setSingular('Posts')
|
|
||||||
->setPlural('Posts')
|
|
||||||
->setProperties([
|
|
||||||
'Id',
|
|
||||||
'Title',
|
|
||||||
'Content',
|
|
||||||
'AuthorId',
|
|
||||||
'CreatedDate',
|
|
||||||
'PublishedDate',
|
|
||||||
'Deleted',
|
|
||||||
])
|
|
||||||
->setAccess(DEFAULT_ROUTE_ACCESS_MODE)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,111 +0,0 @@
|
||||||
<?php
|
|
||||||
$exampleExistingObjectFindFunction = function()
|
|
||||||
{
|
|
||||||
$DIContainer = \⌬\Config\⌬\⌬::Instance()->getContainer();
|
|
||||||
$tableGateway = $DIContainer->get(\Example\BlogApp\TableGateways\UsersTableGateway::class);
|
|
||||||
|
|
||||||
/** @var \Example\BlogApp\TableGateways\UsersTableGateway $exampleExistingObjectTableGateway */
|
|
||||||
$exampleExistingObjectTableGateway = $DIContainer->get(\Example\BlogApp\TableGateways\UsersTableGateway::class);
|
|
||||||
|
|
||||||
/** @var \Example\BlogApp\Models\UsersModel $exampleExistingObject */
|
|
||||||
$exampleExistingObject = $exampleExistingObjectTableGateway->getNewMockModelInstance();
|
|
||||||
if(method_exists($exampleExistingObject, 'setId')){
|
|
||||||
$exampleExistingObject->setId(rand(1000000,9999999));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $exampleExistingObject;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Router proper begins
|
|
||||||
$router = \⌬\Router\Router::Instance()
|
|
||||||
->addRoute(
|
|
||||||
\⌬\Router\Route::Factory()
|
|
||||||
->setName('Users List')
|
|
||||||
->setCallback(\Example\BlogApp\Controllers\UsersController::class . ':listRequest')
|
|
||||||
->setSDKClass('Users')
|
|
||||||
->setSDKFunction('list')
|
|
||||||
->setSDKTemplate('list')
|
|
||||||
->setRouterPattern('/v1/users')
|
|
||||||
->setHttpEndpoint( '/v1/users')
|
|
||||||
->setHttpMethod('GET')
|
|
||||||
->setSingular('Users')
|
|
||||||
->setPlural('Users')
|
|
||||||
->setProperties([
|
|
||||||
'Id',
|
|
||||||
'DisplayName',
|
|
||||||
'UserName',
|
|
||||||
'Email',
|
|
||||||
'Password',
|
|
||||||
])
|
|
||||||
->setPropertyOptions([
|
|
||||||
])
|
|
||||||
->setAccess(DEFAULT_ROUTE_ACCESS_MODE)
|
|
||||||
->setExampleEntityFindFunction($exampleExistingObjectFindFunction)
|
|
||||||
)
|
|
||||||
->addRoute(
|
|
||||||
\⌬\Router\Route::Factory()
|
|
||||||
->setName('Users Create')
|
|
||||||
->setCallback(\Example\BlogApp\Controllers\UsersController::class . ':createRequest')
|
|
||||||
->setSDKClass('Users')
|
|
||||||
->setSDKFunction('create')
|
|
||||||
->setSDKTemplate('create')
|
|
||||||
->setRouterPattern('/v1/users')
|
|
||||||
->setHttpEndpoint( '/v1/users')
|
|
||||||
->setHttpMethod('PUT')
|
|
||||||
->setSingular('Users')
|
|
||||||
->setPlural('Users')
|
|
||||||
->setProperties([
|
|
||||||
'Id',
|
|
||||||
'DisplayName',
|
|
||||||
'UserName',
|
|
||||||
'Email',
|
|
||||||
'Password',
|
|
||||||
])
|
|
||||||
->setAccess(DEFAULT_ROUTE_ACCESS_MODE)
|
|
||||||
->setExampleEntityFindFunction($exampleExistingObjectFindFunction)
|
|
||||||
)
|
|
||||||
->addRoute(
|
|
||||||
\⌬\Router\Route::Factory()
|
|
||||||
->setName('Users Get')
|
|
||||||
->setCallback(\Example\BlogApp\Controllers\UsersController::class . ':getRequest')
|
|
||||||
->setSDKClass('Users')
|
|
||||||
->setSDKFunction('get')
|
|
||||||
->setSDKTemplate('get')
|
|
||||||
->setRouterPattern('/v1/users/{id}')
|
|
||||||
->setHttpEndpoint( '/v1/users/id')
|
|
||||||
->setHttpMethod('GET')
|
|
||||||
->setSingular('Users')
|
|
||||||
->setPlural('Users')
|
|
||||||
->setProperties([
|
|
||||||
'Id',
|
|
||||||
'DisplayName',
|
|
||||||
'UserName',
|
|
||||||
'Email',
|
|
||||||
'Password',
|
|
||||||
])
|
|
||||||
->setAccess(DEFAULT_ROUTE_ACCESS_MODE)
|
|
||||||
->setExampleEntityFindFunction($exampleExistingObjectFindFunction)
|
|
||||||
)
|
|
||||||
->addRoute(
|
|
||||||
\⌬\Router\Route::Factory()
|
|
||||||
->setName('Users Delete')
|
|
||||||
->setCallback(\Example\BlogApp\Controllers\UsersController::class . ':deleteRequest')
|
|
||||||
->setSDKClass('Users')
|
|
||||||
->setSDKFunction('delete')
|
|
||||||
->setSDKTemplate('delete')
|
|
||||||
->setRouterPattern('/v1/users/{id}')
|
|
||||||
->setHttpEndpoint( '/v1/users/id')
|
|
||||||
->setHttpMethod('DELETE')
|
|
||||||
->setSingular('Users')
|
|
||||||
->setPlural('Users')
|
|
||||||
->setProperties([
|
|
||||||
'Id',
|
|
||||||
'DisplayName',
|
|
||||||
'UserName',
|
|
||||||
'Email',
|
|
||||||
'Password',
|
|
||||||
])
|
|
||||||
->setAccess(DEFAULT_ROUTE_ACCESS_MODE)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,221 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Services\Base;
|
|
||||||
|
|
||||||
use ⌬\Controllers\Abstracts\Service as AbstractService;
|
|
||||||
use ⌬\Database\Interfaces\ServiceInterface as ServiceInterface;
|
|
||||||
use \Example\BlogApp\TableGateways;
|
|
||||||
use \Example\BlogApp\Models;
|
|
||||||
use Laminas\Db\ResultSet\ResultSet;
|
|
||||||
use Laminas\Db\Sql\Select;
|
|
||||||
|
|
||||||
/********************************************************
|
|
||||||
* ___ __ *
|
|
||||||
* / _ \___ ____ ___ ____ ____/ / *
|
|
||||||
* / // / _ `/ _ \/ _ `/ -_) __/_/ *
|
|
||||||
* /____/\_,_/_//_/\_, /\__/_/ (_) *
|
|
||||||
* /___/ *
|
|
||||||
* *
|
|
||||||
* Anything in this file is prone to being overwritten! *
|
|
||||||
* *
|
|
||||||
* This file was programatically generated. To modify *
|
|
||||||
* this classes behaviours, do so in the class that *
|
|
||||||
* extends this, or modify the Laminator Template! *
|
|
||||||
********************************************************/
|
|
||||||
// @todo: Make all Services implement a ServicesInterface. - MB
|
|
||||||
abstract class BaseCommentsService
|
|
||||||
extends AbstractService
|
|
||||||
implements ServiceInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
// Related Objects Table Gateways
|
|
||||||
/** @var TableGateways\UsersTableGateway */
|
|
||||||
protected $usersTableGateway;
|
|
||||||
|
|
||||||
// Remote Constraints Table Gateways
|
|
||||||
|
|
||||||
// Self Table Gateway
|
|
||||||
/** @var TableGateways\CommentsTableGateway */
|
|
||||||
protected $commentsTableGateway;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param TableGateways\UsersTableGateway $usersTableGateway
|
|
||||||
* @param TableGateways\CommentsTableGateway $commentsTableGateway
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
TableGateways\UsersTableGateway $usersTableGateway,
|
|
||||||
TableGateways\CommentsTableGateway $commentsTableGateway
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$this->usersTableGateway = $usersTableGateway;
|
|
||||||
$this->commentsTableGateway = $commentsTableGateway;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNewTableGatewayInstance() : TableGateways\CommentsTableGateway
|
|
||||||
{
|
|
||||||
return $this->commentsTableGateway;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNewModelInstance($dataExchange = []) : Models\CommentsModel
|
|
||||||
{
|
|
||||||
return $this->commentsTableGateway->getNewModelInstance($dataExchange);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int|null $limit
|
|
||||||
* @param int|null $offset
|
|
||||||
* @param array|\Closure[]|null $wheres
|
|
||||||
* @param string|Expression|null $order
|
|
||||||
* @param string|null $orderDirection
|
|
||||||
*
|
|
||||||
* @return Models\CommentsModel[]
|
|
||||||
*/
|
|
||||||
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 int $id
|
|
||||||
* @return Models\CommentsModel|null
|
|
||||||
*/
|
|
||||||
public function getById(int $id) : ?Models\CommentsModel
|
|
||||||
{
|
|
||||||
/** @var TableGateways\CommentsTableGateway $commentsTable */
|
|
||||||
$commentsTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $commentsTable->getById($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 Models\CommentsModel|null
|
|
||||||
*/
|
|
||||||
public function getByField(string $field, $value, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING) : ?Models\CommentsModel
|
|
||||||
{
|
|
||||||
/** @var TableGateways\CommentsTableGateway $commentsTable */
|
|
||||||
$commentsTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $commentsTable->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 Models\CommentsModel[]|null
|
|
||||||
*/
|
|
||||||
public function getManyByField(string $field, $value, int $limit = null, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING) : ?array
|
|
||||||
{
|
|
||||||
/** @var TableGateways\CommentsTableGateway $commentsTable */
|
|
||||||
$commentsTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $commentsTable->getManyByField($field, $value, $limit, $orderBy, $orderDirection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $field
|
|
||||||
* @param $value
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function countByField(string $field, $value) : int
|
|
||||||
{
|
|
||||||
$commentsTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $commentsTable->countByField($field, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Models\CommentsModel
|
|
||||||
*/
|
|
||||||
public function getRandom() : ?Models\CommentsModel
|
|
||||||
{
|
|
||||||
/** @var TableGateways\CommentsTableGateway $commentsTable */
|
|
||||||
$commentsTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $commentsTable->fetchRandom();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Where|\Closure|string|array|Predicate\PredicateInterface $keyValue
|
|
||||||
* @param $orderBy string Field to sort by
|
|
||||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
|
||||||
* @return Models\CommentsModel
|
|
||||||
*/
|
|
||||||
public function getMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING) : ?Models\CommentsModel
|
|
||||||
{
|
|
||||||
/** @var TableGateways\CommentsTableGateway $commentsTable */
|
|
||||||
$commentsTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $commentsTable->getMatching($keyValue, $orderBy, $orderDirection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Where|\Closure|string|array|Predicate\PredicateInterface $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\CommentsModel[]
|
|
||||||
*/
|
|
||||||
public function getManyMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING, int $limit = null) : ?array
|
|
||||||
{
|
|
||||||
/** @var TableGateways\CommentsTableGateway $commentsTable */
|
|
||||||
$commentsTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $commentsTable->getManyMatching($keyValue, $orderBy, $orderDirection, $limit);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $dataExchange
|
|
||||||
* @return array|\ArrayObject|null
|
|
||||||
*/
|
|
||||||
public function createFromArray($dataExchange)
|
|
||||||
{
|
|
||||||
/** @var TableGateways\CommentsTableGateway $commentsTable */
|
|
||||||
$commentsTable = $this->getNewTableGatewayInstance();
|
|
||||||
$comments = $this->getNewModelInstance($dataExchange);
|
|
||||||
return $commentsTable->save($comments);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $id
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function deleteByID($id) : int
|
|
||||||
{
|
|
||||||
/** @var TableGateways\CommentsTableGateway $commentsTable */
|
|
||||||
$commentsTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $commentsTable->delete(['id' => $id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTermPlural() : string
|
|
||||||
{
|
|
||||||
return 'Comments';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTermSingular() : string
|
|
||||||
{
|
|
||||||
return 'Comments';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns Models\CommentsModel
|
|
||||||
*/
|
|
||||||
public function getMockObject()
|
|
||||||
{
|
|
||||||
return $this->getNewTableGatewayInstance()->getNewMockModelInstance();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,221 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Services\Base;
|
|
||||||
|
|
||||||
use ⌬\Controllers\Abstracts\Service as AbstractService;
|
|
||||||
use ⌬\Database\Interfaces\ServiceInterface as ServiceInterface;
|
|
||||||
use \Example\BlogApp\TableGateways;
|
|
||||||
use \Example\BlogApp\Models;
|
|
||||||
use Laminas\Db\ResultSet\ResultSet;
|
|
||||||
use Laminas\Db\Sql\Select;
|
|
||||||
|
|
||||||
/********************************************************
|
|
||||||
* ___ __ *
|
|
||||||
* / _ \___ ____ ___ ____ ____/ / *
|
|
||||||
* / // / _ `/ _ \/ _ `/ -_) __/_/ *
|
|
||||||
* /____/\_,_/_//_/\_, /\__/_/ (_) *
|
|
||||||
* /___/ *
|
|
||||||
* *
|
|
||||||
* Anything in this file is prone to being overwritten! *
|
|
||||||
* *
|
|
||||||
* This file was programatically generated. To modify *
|
|
||||||
* this classes behaviours, do so in the class that *
|
|
||||||
* extends this, or modify the Laminator Template! *
|
|
||||||
********************************************************/
|
|
||||||
// @todo: Make all Services implement a ServicesInterface. - MB
|
|
||||||
abstract class BasePostsService
|
|
||||||
extends AbstractService
|
|
||||||
implements ServiceInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
// Related Objects Table Gateways
|
|
||||||
/** @var TableGateways\UsersTableGateway */
|
|
||||||
protected $usersTableGateway;
|
|
||||||
|
|
||||||
// Remote Constraints Table Gateways
|
|
||||||
|
|
||||||
// Self Table Gateway
|
|
||||||
/** @var TableGateways\PostsTableGateway */
|
|
||||||
protected $postsTableGateway;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param TableGateways\UsersTableGateway $usersTableGateway
|
|
||||||
* @param TableGateways\PostsTableGateway $postsTableGateway
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
TableGateways\UsersTableGateway $usersTableGateway,
|
|
||||||
TableGateways\PostsTableGateway $postsTableGateway
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$this->usersTableGateway = $usersTableGateway;
|
|
||||||
$this->postsTableGateway = $postsTableGateway;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNewTableGatewayInstance() : TableGateways\PostsTableGateway
|
|
||||||
{
|
|
||||||
return $this->postsTableGateway;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNewModelInstance($dataExchange = []) : Models\PostsModel
|
|
||||||
{
|
|
||||||
return $this->postsTableGateway->getNewModelInstance($dataExchange);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int|null $limit
|
|
||||||
* @param int|null $offset
|
|
||||||
* @param array|\Closure[]|null $wheres
|
|
||||||
* @param string|Expression|null $order
|
|
||||||
* @param string|null $orderDirection
|
|
||||||
*
|
|
||||||
* @return Models\PostsModel[]
|
|
||||||
*/
|
|
||||||
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 int $id
|
|
||||||
* @return Models\PostsModel|null
|
|
||||||
*/
|
|
||||||
public function getById(int $id) : ?Models\PostsModel
|
|
||||||
{
|
|
||||||
/** @var TableGateways\PostsTableGateway $postsTable */
|
|
||||||
$postsTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $postsTable->getById($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 Models\PostsModel|null
|
|
||||||
*/
|
|
||||||
public function getByField(string $field, $value, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING) : ?Models\PostsModel
|
|
||||||
{
|
|
||||||
/** @var TableGateways\PostsTableGateway $postsTable */
|
|
||||||
$postsTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $postsTable->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 Models\PostsModel[]|null
|
|
||||||
*/
|
|
||||||
public function getManyByField(string $field, $value, int $limit = null, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING) : ?array
|
|
||||||
{
|
|
||||||
/** @var TableGateways\PostsTableGateway $postsTable */
|
|
||||||
$postsTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $postsTable->getManyByField($field, $value, $limit, $orderBy, $orderDirection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $field
|
|
||||||
* @param $value
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function countByField(string $field, $value) : int
|
|
||||||
{
|
|
||||||
$postsTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $postsTable->countByField($field, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Models\PostsModel
|
|
||||||
*/
|
|
||||||
public function getRandom() : ?Models\PostsModel
|
|
||||||
{
|
|
||||||
/** @var TableGateways\PostsTableGateway $postsTable */
|
|
||||||
$postsTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $postsTable->fetchRandom();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Where|\Closure|string|array|Predicate\PredicateInterface $keyValue
|
|
||||||
* @param $orderBy string Field to sort by
|
|
||||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
|
||||||
* @return Models\PostsModel
|
|
||||||
*/
|
|
||||||
public function getMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING) : ?Models\PostsModel
|
|
||||||
{
|
|
||||||
/** @var TableGateways\PostsTableGateway $postsTable */
|
|
||||||
$postsTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $postsTable->getMatching($keyValue, $orderBy, $orderDirection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Where|\Closure|string|array|Predicate\PredicateInterface $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\PostsModel[]
|
|
||||||
*/
|
|
||||||
public function getManyMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING, int $limit = null) : ?array
|
|
||||||
{
|
|
||||||
/** @var TableGateways\PostsTableGateway $postsTable */
|
|
||||||
$postsTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $postsTable->getManyMatching($keyValue, $orderBy, $orderDirection, $limit);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $dataExchange
|
|
||||||
* @return array|\ArrayObject|null
|
|
||||||
*/
|
|
||||||
public function createFromArray($dataExchange)
|
|
||||||
{
|
|
||||||
/** @var TableGateways\PostsTableGateway $postsTable */
|
|
||||||
$postsTable = $this->getNewTableGatewayInstance();
|
|
||||||
$posts = $this->getNewModelInstance($dataExchange);
|
|
||||||
return $postsTable->save($posts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $id
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function deleteByID($id) : int
|
|
||||||
{
|
|
||||||
/** @var TableGateways\PostsTableGateway $postsTable */
|
|
||||||
$postsTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $postsTable->delete(['id' => $id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTermPlural() : string
|
|
||||||
{
|
|
||||||
return 'Posts';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTermSingular() : string
|
|
||||||
{
|
|
||||||
return 'Posts';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns Models\PostsModel
|
|
||||||
*/
|
|
||||||
public function getMockObject()
|
|
||||||
{
|
|
||||||
return $this->getNewTableGatewayInstance()->getNewMockModelInstance();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,216 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Services\Base;
|
|
||||||
|
|
||||||
use ⌬\Controllers\Abstracts\Service as AbstractService;
|
|
||||||
use ⌬\Database\Interfaces\ServiceInterface as ServiceInterface;
|
|
||||||
use \Example\BlogApp\TableGateways;
|
|
||||||
use \Example\BlogApp\Models;
|
|
||||||
use Laminas\Db\ResultSet\ResultSet;
|
|
||||||
use Laminas\Db\Sql\Select;
|
|
||||||
|
|
||||||
/********************************************************
|
|
||||||
* ___ __ *
|
|
||||||
* / _ \___ ____ ___ ____ ____/ / *
|
|
||||||
* / // / _ `/ _ \/ _ `/ -_) __/_/ *
|
|
||||||
* /____/\_,_/_//_/\_, /\__/_/ (_) *
|
|
||||||
* /___/ *
|
|
||||||
* *
|
|
||||||
* Anything in this file is prone to being overwritten! *
|
|
||||||
* *
|
|
||||||
* This file was programatically generated. To modify *
|
|
||||||
* this classes behaviours, do so in the class that *
|
|
||||||
* extends this, or modify the Laminator Template! *
|
|
||||||
********************************************************/
|
|
||||||
// @todo: Make all Services implement a ServicesInterface. - MB
|
|
||||||
abstract class BaseUsersService
|
|
||||||
extends AbstractService
|
|
||||||
implements ServiceInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
// Related Objects Table Gateways
|
|
||||||
|
|
||||||
// Remote Constraints Table Gateways
|
|
||||||
|
|
||||||
// Self Table Gateway
|
|
||||||
/** @var TableGateways\UsersTableGateway */
|
|
||||||
protected $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 int|null $limit
|
|
||||||
* @param int|null $offset
|
|
||||||
* @param array|\Closure[]|null $wheres
|
|
||||||
* @param string|Expression|null $order
|
|
||||||
* @param string|null $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 int $id
|
|
||||||
* @return Models\UsersModel|null
|
|
||||||
*/
|
|
||||||
public function getById(int $id) : ?Models\UsersModel
|
|
||||||
{
|
|
||||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
|
||||||
$usersTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $usersTable->getById($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 Models\UsersModel|null
|
|
||||||
*/
|
|
||||||
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 Models\UsersModel[]|null
|
|
||||||
*/
|
|
||||||
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 Where|\Closure|string|array|Predicate\PredicateInterface $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 Where|\Closure|string|array|Predicate\PredicateInterface $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 array|\ArrayObject|null
|
|
||||||
*/
|
|
||||||
public function createFromArray($dataExchange)
|
|
||||||
{
|
|
||||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
|
||||||
$usersTable = $this->getNewTableGatewayInstance();
|
|
||||||
$users = $this->getNewModelInstance($dataExchange);
|
|
||||||
return $usersTable->save($users);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $id
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function deleteByID($id) : int
|
|
||||||
{
|
|
||||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
|
||||||
$usersTable = $this->getNewTableGatewayInstance();
|
|
||||||
return $usersTable->delete(['id' => $id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTermPlural() : string
|
|
||||||
{
|
|
||||||
return 'Users';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTermSingular() : string
|
|
||||||
{
|
|
||||||
return 'Users';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns Models\UsersModel
|
|
||||||
*/
|
|
||||||
public function getMockObject()
|
|
||||||
{
|
|
||||||
return $this->getNewTableGatewayInstance()->getNewMockModelInstance();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Services;
|
|
||||||
|
|
||||||
use Example\BlogApp\Services\Base\BaseCommentsService;
|
|
||||||
|
|
||||||
class CommentsService extends BaseCommentsService
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Services;
|
|
||||||
|
|
||||||
use Example\BlogApp\Services\Base\BasePostsService;
|
|
||||||
|
|
||||||
class PostsService extends BasePostsService
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Services;
|
|
||||||
|
|
||||||
use Example\BlogApp\Services\Base\BaseUsersService;
|
|
||||||
|
|
||||||
class UsersService extends BaseUsersService
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,112 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\TableGateways\Base;
|
|
||||||
use \⌬\Controllers\Abstracts\TableGateway as AbstractTableGateway;
|
|
||||||
use \⌬\Controllers\Abstracts\Model;
|
|
||||||
use \⌬\Database\Db;
|
|
||||||
use \Example\BlogApp\TableGateways;
|
|
||||||
use \Example\BlogApp\Models;
|
|
||||||
use \Laminas\Db\Adapter\AdapterInterface;
|
|
||||||
use \Laminas\Db\ResultSet\ResultSet;
|
|
||||||
use \Gone\AppCore\Exceptions;
|
|
||||||
|
|
||||||
/********************************************************
|
|
||||||
* ___ __ *
|
|
||||||
* / _ \___ ____ ___ ____ ____/ / *
|
|
||||||
* / // / _ `/ _ \/ _ `/ -_) __/_/ *
|
|
||||||
* /____/\_,_/_//_/\_, /\__/_/ (_) *
|
|
||||||
* /___/ *
|
|
||||||
* *
|
|
||||||
* Anything in this file is prone to being overwritten! *
|
|
||||||
* *
|
|
||||||
* This file was programatically generated. To modify *
|
|
||||||
* this classes behaviours, do so in the class that *
|
|
||||||
* extends this, or modify the Laminator Template! *
|
|
||||||
********************************************************/
|
|
||||||
// @todo: Make all TableGateways implement a TableGatewayInterface. -MB
|
|
||||||
abstract class BaseCommentsTableGateway extends AbstractTableGateway
|
|
||||||
{
|
|
||||||
protected $table = 'comments';
|
|
||||||
|
|
||||||
protected $database = 'mysql';
|
|
||||||
|
|
||||||
protected $model = Models\CommentsModel::class;
|
|
||||||
|
|
||||||
/** @var \Faker\Generator */
|
|
||||||
protected $faker;
|
|
||||||
|
|
||||||
/** @var Db */
|
|
||||||
private $databaseConnector;
|
|
||||||
|
|
||||||
private $databaseAdaptor;
|
|
||||||
|
|
||||||
/** @var TableGateways\UsersTableGateway */
|
|
||||||
protected $usersTableGateway;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AbstractTableGateway constructor.
|
|
||||||
*
|
|
||||||
* @param TableGateways\UsersTableGateway $usersTableGateway,
|
|
||||||
* @param Db $databaseConnector
|
|
||||||
*
|
|
||||||
* @throws Exceptions\DbException
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
TableGateways\UsersTableGateway $usersTableGateway,
|
|
||||||
\Faker\Generator $faker,
|
|
||||||
Db $databaseConnector
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$this->usersTableGateway = $usersTableGateway;
|
|
||||||
$this->faker = $faker;
|
|
||||||
$this->databaseConnector = $databaseConnector;
|
|
||||||
|
|
||||||
/** @var $adaptor AdapterInterface */
|
|
||||||
// @todo rename all uses of 'adaptor' to 'adapter'. I cannot spell - MB
|
|
||||||
$this->databaseAdaptor = $this->databaseConnector->getDatabase($this->database);
|
|
||||||
$resultSetPrototype = new ResultSet(ResultSet::TYPE_ARRAYOBJECT, new $this->model);
|
|
||||||
return parent::__construct($this->table, $this->databaseAdaptor, null, $resultSetPrototype);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Models\CommentsModel
|
|
||||||
*/
|
|
||||||
public function getNewMockModelInstance()
|
|
||||||
{
|
|
||||||
// Generate a Random Users.
|
|
||||||
$randomUsers = $this->usersTableGateway->fetchRandom();
|
|
||||||
|
|
||||||
$newCommentsData = [
|
|
||||||
// authorId. Type = int. PHPType = int. Has related objects.
|
|
||||||
'authorId' =>
|
|
||||||
$randomUsers instanceof Models\UsersModel
|
|
||||||
? $this->usersTableGateway->fetchRandom()->getId()
|
|
||||||
: $this->usersTableGateway->getNewMockModelInstance()->save()->getId(),
|
|
||||||
|
|
||||||
// comment. Type = text. PHPType = string. Has no related objects.
|
|
||||||
'comment' => substr($this->faker->text(500 >= 5 ? 500 : 5), 0, 500),
|
|
||||||
// id. Type = int. PHPType = int. Has no related objects.
|
|
||||||
// publishedDate. Type = datetime. PHPType = string. Has no related objects.
|
|
||||||
'publishedDate' => $this->faker->dateTime()->format("Y-m-d H:i:s"), // @todo: Make datetime fields accept DateTime objects instead of strings. - MB
|
|
||||||
];
|
|
||||||
$newComments = $this->getNewModelInstance($newCommentsData);
|
|
||||||
return $newComments;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data
|
|
||||||
* @return Models\CommentsModel
|
|
||||||
*/
|
|
||||||
public function getNewModelInstance(array $data = [])
|
|
||||||
{
|
|
||||||
return parent::getNewModelInstance($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Models\CommentsModel $model
|
|
||||||
* @return Models\CommentsModel
|
|
||||||
*/
|
|
||||||
public function save(Model $model)
|
|
||||||
{
|
|
||||||
return parent::save($model);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,118 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\TableGateways\Base;
|
|
||||||
use \⌬\Controllers\Abstracts\TableGateway as AbstractTableGateway;
|
|
||||||
use \⌬\Controllers\Abstracts\Model;
|
|
||||||
use \⌬\Database\Db;
|
|
||||||
use \Example\BlogApp\TableGateways;
|
|
||||||
use \Example\BlogApp\Models;
|
|
||||||
use \Laminas\Db\Adapter\AdapterInterface;
|
|
||||||
use \Laminas\Db\ResultSet\ResultSet;
|
|
||||||
use \Gone\AppCore\Exceptions;
|
|
||||||
|
|
||||||
/********************************************************
|
|
||||||
* ___ __ *
|
|
||||||
* / _ \___ ____ ___ ____ ____/ / *
|
|
||||||
* / // / _ `/ _ \/ _ `/ -_) __/_/ *
|
|
||||||
* /____/\_,_/_//_/\_, /\__/_/ (_) *
|
|
||||||
* /___/ *
|
|
||||||
* *
|
|
||||||
* Anything in this file is prone to being overwritten! *
|
|
||||||
* *
|
|
||||||
* This file was programatically generated. To modify *
|
|
||||||
* this classes behaviours, do so in the class that *
|
|
||||||
* extends this, or modify the Laminator Template! *
|
|
||||||
********************************************************/
|
|
||||||
// @todo: Make all TableGateways implement a TableGatewayInterface. -MB
|
|
||||||
abstract class BasePostsTableGateway extends AbstractTableGateway
|
|
||||||
{
|
|
||||||
protected $table = 'posts';
|
|
||||||
|
|
||||||
protected $database = 'mysql';
|
|
||||||
|
|
||||||
protected $model = Models\PostsModel::class;
|
|
||||||
|
|
||||||
/** @var \Faker\Generator */
|
|
||||||
protected $faker;
|
|
||||||
|
|
||||||
/** @var Db */
|
|
||||||
private $databaseConnector;
|
|
||||||
|
|
||||||
private $databaseAdaptor;
|
|
||||||
|
|
||||||
/** @var TableGateways\UsersTableGateway */
|
|
||||||
protected $usersTableGateway;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AbstractTableGateway constructor.
|
|
||||||
*
|
|
||||||
* @param TableGateways\UsersTableGateway $usersTableGateway,
|
|
||||||
* @param Db $databaseConnector
|
|
||||||
*
|
|
||||||
* @throws Exceptions\DbException
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
TableGateways\UsersTableGateway $usersTableGateway,
|
|
||||||
\Faker\Generator $faker,
|
|
||||||
Db $databaseConnector
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$this->usersTableGateway = $usersTableGateway;
|
|
||||||
$this->faker = $faker;
|
|
||||||
$this->databaseConnector = $databaseConnector;
|
|
||||||
|
|
||||||
/** @var $adaptor AdapterInterface */
|
|
||||||
// @todo rename all uses of 'adaptor' to 'adapter'. I cannot spell - MB
|
|
||||||
$this->databaseAdaptor = $this->databaseConnector->getDatabase($this->database);
|
|
||||||
$resultSetPrototype = new ResultSet(ResultSet::TYPE_ARRAYOBJECT, new $this->model);
|
|
||||||
return parent::__construct($this->table, $this->databaseAdaptor, null, $resultSetPrototype);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Models\PostsModel
|
|
||||||
*/
|
|
||||||
public function getNewMockModelInstance()
|
|
||||||
{
|
|
||||||
// Generate a Random Users.
|
|
||||||
$randomUsers = $this->usersTableGateway->fetchRandom();
|
|
||||||
|
|
||||||
$newPostsData = [
|
|
||||||
// authorId. Type = int. PHPType = int. Has related objects.
|
|
||||||
'authorId' =>
|
|
||||||
$randomUsers instanceof Models\UsersModel
|
|
||||||
? $this->usersTableGateway->fetchRandom()->getId()
|
|
||||||
: $this->usersTableGateway->getNewMockModelInstance()->save()->getId(),
|
|
||||||
|
|
||||||
// content. Type = text. PHPType = string. Has no related objects.
|
|
||||||
'content' => substr($this->faker->text(500 >= 5 ? 500 : 5), 0, 500),
|
|
||||||
// createdDate. Type = datetime. PHPType = string. Has no related objects.
|
|
||||||
'createdDate' => $this->faker->dateTime()->format("Y-m-d H:i:s"), // @todo: Make datetime fields accept DateTime objects instead of strings. - MB
|
|
||||||
// deleted. Type = enum. PHPType = string. Has no related objects.
|
|
||||||
'deleted' => 'Yes',
|
|
||||||
// id. Type = int. PHPType = int. Has no related objects.
|
|
||||||
// publishedDate. Type = datetime. PHPType = string. Has no related objects.
|
|
||||||
'publishedDate' => $this->faker->dateTime()->format("Y-m-d H:i:s"), // @todo: Make datetime fields accept DateTime objects instead of strings. - MB
|
|
||||||
// title. Type = text. PHPType = string. Has no related objects.
|
|
||||||
'title' => substr($this->faker->text(500 >= 5 ? 500 : 5), 0, 500),
|
|
||||||
];
|
|
||||||
$newPosts = $this->getNewModelInstance($newPostsData);
|
|
||||||
return $newPosts;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data
|
|
||||||
* @return Models\PostsModel
|
|
||||||
*/
|
|
||||||
public function getNewModelInstance(array $data = [])
|
|
||||||
{
|
|
||||||
return parent::getNewModelInstance($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Models\PostsModel $model
|
|
||||||
* @return Models\PostsModel
|
|
||||||
*/
|
|
||||||
public function save(Model $model)
|
|
||||||
{
|
|
||||||
return parent::save($model);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,102 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\TableGateways\Base;
|
|
||||||
use \⌬\Controllers\Abstracts\TableGateway as AbstractTableGateway;
|
|
||||||
use \⌬\Controllers\Abstracts\Model;
|
|
||||||
use \⌬\Database\Db;
|
|
||||||
use \Example\BlogApp\TableGateways;
|
|
||||||
use \Example\BlogApp\Models;
|
|
||||||
use \Laminas\Db\Adapter\AdapterInterface;
|
|
||||||
use \Laminas\Db\ResultSet\ResultSet;
|
|
||||||
use \Gone\AppCore\Exceptions;
|
|
||||||
|
|
||||||
/********************************************************
|
|
||||||
* ___ __ *
|
|
||||||
* / _ \___ ____ ___ ____ ____/ / *
|
|
||||||
* / // / _ `/ _ \/ _ `/ -_) __/_/ *
|
|
||||||
* /____/\_,_/_//_/\_, /\__/_/ (_) *
|
|
||||||
* /___/ *
|
|
||||||
* *
|
|
||||||
* Anything in this file is prone to being overwritten! *
|
|
||||||
* *
|
|
||||||
* This file was programatically generated. To modify *
|
|
||||||
* this classes behaviours, do so in the class that *
|
|
||||||
* extends this, or modify the Laminator Template! *
|
|
||||||
********************************************************/
|
|
||||||
// @todo: Make all TableGateways implement a TableGatewayInterface. -MB
|
|
||||||
abstract class BaseUsersTableGateway extends AbstractTableGateway
|
|
||||||
{
|
|
||||||
protected $table = 'users';
|
|
||||||
|
|
||||||
protected $database = 'mysql';
|
|
||||||
|
|
||||||
protected $model = Models\UsersModel::class;
|
|
||||||
|
|
||||||
/** @var \Faker\Generator */
|
|
||||||
protected $faker;
|
|
||||||
|
|
||||||
/** @var Db */
|
|
||||||
private $databaseConnector;
|
|
||||||
|
|
||||||
private $databaseAdaptor;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AbstractTableGateway constructor.
|
|
||||||
*
|
|
||||||
* @param Db $databaseConnector
|
|
||||||
*
|
|
||||||
* @throws Exceptions\DbException
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
\Faker\Generator $faker,
|
|
||||||
Db $databaseConnector
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$this->faker = $faker;
|
|
||||||
$this->databaseConnector = $databaseConnector;
|
|
||||||
|
|
||||||
/** @var $adaptor AdapterInterface */
|
|
||||||
// @todo rename all uses of 'adaptor' to 'adapter'. I cannot spell - MB
|
|
||||||
$this->databaseAdaptor = $this->databaseConnector->getDatabase($this->database);
|
|
||||||
$resultSetPrototype = new ResultSet(ResultSet::TYPE_ARRAYOBJECT, new $this->model);
|
|
||||||
return parent::__construct($this->table, $this->databaseAdaptor, null, $resultSetPrototype);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Models\UsersModel
|
|
||||||
*/
|
|
||||||
public function getNewMockModelInstance()
|
|
||||||
{
|
|
||||||
$newUsersData = [
|
|
||||||
// displayName. Type = varchar. PHPType = string. Has no related objects.
|
|
||||||
'displayName' => substr($this->faker->text(45 >= 5 ? 45 : 5), 0, 45),
|
|
||||||
// email. Type = varchar. PHPType = string. Has no related objects.
|
|
||||||
'email' => substr($this->faker->text(320 >= 5 ? 320 : 5), 0, 320),
|
|
||||||
// id. Type = int. PHPType = int. Has no related objects.
|
|
||||||
// password. Type = varchar. PHPType = string. Has no related objects.
|
|
||||||
'password' => substr($this->faker->text(200 >= 5 ? 200 : 5), 0, 200),
|
|
||||||
// userName. Type = varchar. PHPType = string. Has no related objects.
|
|
||||||
'userName' => substr($this->faker->text(45 >= 5 ? 45 : 5), 0, 45),
|
|
||||||
];
|
|
||||||
$newUsers = $this->getNewModelInstance($newUsersData);
|
|
||||||
return $newUsers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data
|
|
||||||
* @return Models\UsersModel
|
|
||||||
*/
|
|
||||||
public function getNewModelInstance(array $data = [])
|
|
||||||
{
|
|
||||||
return parent::getNewModelInstance($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Models\UsersModel $model
|
|
||||||
* @return Models\UsersModel
|
|
||||||
*/
|
|
||||||
public function save(Model $model)
|
|
||||||
{
|
|
||||||
return parent::save($model);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\TableGateways;
|
|
||||||
use Example\BlogApp\TableGateways\Base\BaseCommentsTableGateway;
|
|
||||||
|
|
||||||
class CommentsTableGateway extends BaseCommentsTableGateway
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\TableGateways;
|
|
||||||
use Example\BlogApp\TableGateways\Base\BasePostsTableGateway;
|
|
||||||
|
|
||||||
class PostsTableGateway extends BasePostsTableGateway
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\TableGateways;
|
|
||||||
use Example\BlogApp\TableGateways\Base\BaseUsersTableGateway;
|
|
||||||
|
|
||||||
class UsersTableGateway extends BaseUsersTableGateway
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,205 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Example\BlogApp\Test\Api\Generated;
|
|
||||||
|
|
||||||
use Example\BlogApp\TableGateways;
|
|
||||||
use Example\BlogApp\Models\CommentsModel;
|
|
||||||
use Example\BlogApp\Services\CommentsService;
|
|
||||||
use ⌬\Tests\RoutesTestCase;
|
|
||||||
|
|
||||||
class CommentsEndpointTest extends RoutesTestCase
|
|
||||||
{
|
|
||||||
|
|
||||||
const MODEL_NAME = 'Comments';
|
|
||||||
|
|
||||||
public function testCommentsCreate()
|
|
||||||
{
|
|
||||||
$this->waypoint("Begin");
|
|
||||||
/** @var CommentsService $service */
|
|
||||||
$service = $this->getApp()->getContainer()->get(CommentsService::class);
|
|
||||||
/** @var CommentsModel $newComments **/
|
|
||||||
$newComments = $service->getMockObject();
|
|
||||||
|
|
||||||
$this->waypoint("Initialise Mock Model");
|
|
||||||
$newCommentsArray = $newComments->__toArray();
|
|
||||||
|
|
||||||
$method = "PUT";
|
|
||||||
$uri = "/v1/comments";
|
|
||||||
|
|
||||||
$response = $this->request(
|
|
||||||
$method,
|
|
||||||
$uri,
|
|
||||||
$newCommentsArray
|
|
||||||
);
|
|
||||||
$this->waypoint("API PUT REST REQUEST");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
\Kint::dump(
|
|
||||||
$newCommentsArray,
|
|
||||||
json_encode($newCommentsArray, JSON_PRETTY_PRINT)
|
|
||||||
);
|
|
||||||
$requestCommentsParams = ob_get_contents();
|
|
||||||
ob_end_clean();
|
|
||||||
|
|
||||||
$this->assertTrue(
|
|
||||||
in_array(
|
|
||||||
$response->getStatusCode(),
|
|
||||||
[
|
|
||||||
200,
|
|
||||||
400,
|
|
||||||
]
|
|
||||||
),
|
|
||||||
"Response was not expected 200 or 400.\n" .
|
|
||||||
"Request: {$method} => {$uri}" .
|
|
||||||
"{$requestCommentsParams}\n" .
|
|
||||||
"Response body is: \n" .
|
|
||||||
" ******************************\n{$body}\n ******************************\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->waypoint("Get & Parse Response");
|
|
||||||
$this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\" Request JSON blob: \"" . json_encode($newComments->__toArray()) . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode($body, true);
|
|
||||||
$this->waypoint("JSON DECODE");
|
|
||||||
$this->assertArrayHasKey('Status', $responseJson);
|
|
||||||
$this->assertEquals("Okay", $responseJson['Status'], "Verify that request to PUT /v1/comments returns an \"Status: Okay\" response. This failed. " . (isset($responseJson['Reason']) ? "Reason: " . $responseJson['Reason'] : "No Reason Given"));
|
|
||||||
$this->assertArrayHasKey('Comments', $responseJson);
|
|
||||||
$this->waypoint("Some assertions");
|
|
||||||
|
|
||||||
#\Kint::dump(
|
|
||||||
# $newCommentsArray,
|
|
||||||
# $responseJson
|
|
||||||
#);
|
|
||||||
|
|
||||||
$this->validateCommentsObject($responseJson['Comments']);
|
|
||||||
$this->waypoint("Validate Object Response");
|
|
||||||
//TODO: Make this respect primary key field instead of assuming ID.
|
|
||||||
if(!isset($responseJson['Comments']['Id'])){
|
|
||||||
$this->markTestIncomplete("Skipped test... Comments response object doesn't have an ID field.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $responseJson['Comments']['Id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function testCommentsCreateFails()
|
|
||||||
{
|
|
||||||
$this->waypoint("Begin");
|
|
||||||
|
|
||||||
$newComments = [
|
|
||||||
'id' => null,
|
|
||||||
'comment' => null,
|
|
||||||
'authorId' => null,
|
|
||||||
'publishedDate' => null,
|
|
||||||
];
|
|
||||||
$response = $this->request("PUT", "/v1/comments", $newComments);
|
|
||||||
$this->waypoint("API PUT REST REQUEST");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
$this->assertTrue(in_array($response->getStatusCode(), [200,400]), "Response was not expected 200 or 400. Response body is: \n\n" . $body . "\n\n"); $this->waypoint("Get & Parse Response");
|
|
||||||
$this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\" Request JSON blob: \"" . json_encode($newComments) . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode((string)$body, true);
|
|
||||||
$this->waypoint("JSON DECODE");
|
|
||||||
$this->assertArrayHasKey('Status', $responseJson);
|
|
||||||
$this->assertEquals("Fail", $responseJson['Status'], "Object was created, when failure was expected.");
|
|
||||||
$this->waypoint("Some assertions");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testCommentsCreate
|
|
||||||
*/
|
|
||||||
public function testCommentsGet($id)
|
|
||||||
{
|
|
||||||
$this->waypoint("Begin");
|
|
||||||
$response = $this->request("GET", "/v1/comments/{$id}");
|
|
||||||
$this->waypoint("API GET REST REQUEST");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
$this->assertTrue(in_array($response->getStatusCode(), [200,400]), "Response was not expected 200 or 400. Response body is: \n\n" . $body . "\n\n"); $this->waypoint("Get & Parse Response");
|
|
||||||
$this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode((string)$body, true);
|
|
||||||
$this->waypoint("JSON DECODE");
|
|
||||||
$this->assertArrayHasKey('Status', $responseJson);
|
|
||||||
$this->assertEquals("Okay", $responseJson['Status'], "Verify that request to GET /v1/comments/{$id} returns an \"Status: Okay\" response. This failed. " . (isset($responseJson['Reason']) ? "Reason: " . $responseJson['Reason'] : "No Reason Given"));
|
|
||||||
$this->assertArrayHasKey('Comments', $responseJson);
|
|
||||||
$this->waypoint("Some assertions");
|
|
||||||
|
|
||||||
$this->validateCommentsObject($responseJson['Comments']);
|
|
||||||
$this->waypoint("Validate Object Response");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testCommentsCreate
|
|
||||||
*/
|
|
||||||
public function testCommentsList()
|
|
||||||
{
|
|
||||||
$this->waypoint("Begin");
|
|
||||||
$response = $this->request("GET", "/v1/comments");
|
|
||||||
$this->waypoint("API REST REQUEST");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
$this->assertTrue(in_array($response->getStatusCode(), [200,400]), "Response was not expected 200 or 400. Response body is: \n\n" . $body . "\n\n"); $this->waypoint("Get & Parse Response");
|
|
||||||
$this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode((string)$body, true);
|
|
||||||
$this->waypoint("JSON DECODE");
|
|
||||||
$this->assertArrayHasKey('Status', $responseJson);
|
|
||||||
$this->assertEquals("Okay", $responseJson['Status'], "Verify that request to GET /v1/comments returns an \"Status: Okay\" response. This failed. " . (isset($responseJson['Reason']) ? "Reason: " . $responseJson['Reason'] : "No Reason Given"));
|
|
||||||
$this->assertArrayHasKey('Comments', $responseJson);
|
|
||||||
$this->waypoint("Some assertions");
|
|
||||||
$this->validateCommentsObject(reset($responseJson['Comments']));
|
|
||||||
$this->waypoint("Validate Object Response");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testCommentsCreate
|
|
||||||
*/
|
|
||||||
public function testCommentsDelete($id)
|
|
||||||
{
|
|
||||||
$response = $this->request("DELETE", "/v1/comments/{$id}");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
$this->assertTrue(in_array($response->getStatusCode(), [200,400]), "Response was not expected 200 or 400. Response body is: \n\n" . $body . "\n\n"); $this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode((string)$body, true);
|
|
||||||
$this->assertArrayHasKey('Status', $responseJson);
|
|
||||||
$this->assertEquals("Okay", $responseJson['Status'], "Verify that request to DELETE /v1/comments/{$id} returns an \"Status: Okay\" response. This failed. " . (isset($responseJson['Reason']) ? "Reason: " . $responseJson['Reason'] : "No Reason Given"));
|
|
||||||
$this->assertEquals("DELETE", $responseJson['Action']);
|
|
||||||
$this->assertArrayHasKey('Comments', $responseJson);
|
|
||||||
$this->validateCommentsObject($responseJson['Comments']);
|
|
||||||
return $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testCommentsDelete
|
|
||||||
*/
|
|
||||||
public function testCommentsDeleteVerify($id)
|
|
||||||
{
|
|
||||||
$response = $this->request("GET", "/v1/comments/{$id}");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
$this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode((string)$body, true);
|
|
||||||
$this->assertEquals("Fail", $responseJson['Status']);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function validateCommentsObject($CommentsObject)
|
|
||||||
{
|
|
||||||
$this->assertArrayHasKey('Id', $CommentsObject, "There was no element with the key 'id'.");
|
|
||||||
$this->assertArrayHasKey('Comment', $CommentsObject, "There was no element with the key 'comment'.");
|
|
||||||
$this->assertArrayHasKey('AuthorId', $CommentsObject, "There was no element with the key 'authorId'.");
|
|
||||||
$this->assertArrayHasKey('PublishedDate', $CommentsObject, "There was no element with the key 'publishedDate'.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,211 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Example\BlogApp\Test\Api\Generated;
|
|
||||||
|
|
||||||
use Example\BlogApp\TableGateways;
|
|
||||||
use Example\BlogApp\Models\PostsModel;
|
|
||||||
use Example\BlogApp\Services\PostsService;
|
|
||||||
use ⌬\Tests\RoutesTestCase;
|
|
||||||
|
|
||||||
class PostsEndpointTest extends RoutesTestCase
|
|
||||||
{
|
|
||||||
|
|
||||||
const MODEL_NAME = 'Posts';
|
|
||||||
|
|
||||||
public function testPostsCreate()
|
|
||||||
{
|
|
||||||
$this->waypoint("Begin");
|
|
||||||
/** @var PostsService $service */
|
|
||||||
$service = $this->getApp()->getContainer()->get(PostsService::class);
|
|
||||||
/** @var PostsModel $newPosts **/
|
|
||||||
$newPosts = $service->getMockObject();
|
|
||||||
|
|
||||||
$this->waypoint("Initialise Mock Model");
|
|
||||||
$newPostsArray = $newPosts->__toArray();
|
|
||||||
|
|
||||||
$method = "PUT";
|
|
||||||
$uri = "/v1/posts";
|
|
||||||
|
|
||||||
$response = $this->request(
|
|
||||||
$method,
|
|
||||||
$uri,
|
|
||||||
$newPostsArray
|
|
||||||
);
|
|
||||||
$this->waypoint("API PUT REST REQUEST");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
\Kint::dump(
|
|
||||||
$newPostsArray,
|
|
||||||
json_encode($newPostsArray, JSON_PRETTY_PRINT)
|
|
||||||
);
|
|
||||||
$requestPostsParams = ob_get_contents();
|
|
||||||
ob_end_clean();
|
|
||||||
|
|
||||||
$this->assertTrue(
|
|
||||||
in_array(
|
|
||||||
$response->getStatusCode(),
|
|
||||||
[
|
|
||||||
200,
|
|
||||||
400,
|
|
||||||
]
|
|
||||||
),
|
|
||||||
"Response was not expected 200 or 400.\n" .
|
|
||||||
"Request: {$method} => {$uri}" .
|
|
||||||
"{$requestPostsParams}\n" .
|
|
||||||
"Response body is: \n" .
|
|
||||||
" ******************************\n{$body}\n ******************************\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->waypoint("Get & Parse Response");
|
|
||||||
$this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\" Request JSON blob: \"" . json_encode($newPosts->__toArray()) . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode($body, true);
|
|
||||||
$this->waypoint("JSON DECODE");
|
|
||||||
$this->assertArrayHasKey('Status', $responseJson);
|
|
||||||
$this->assertEquals("Okay", $responseJson['Status'], "Verify that request to PUT /v1/posts returns an \"Status: Okay\" response. This failed. " . (isset($responseJson['Reason']) ? "Reason: " . $responseJson['Reason'] : "No Reason Given"));
|
|
||||||
$this->assertArrayHasKey('Posts', $responseJson);
|
|
||||||
$this->waypoint("Some assertions");
|
|
||||||
|
|
||||||
#\Kint::dump(
|
|
||||||
# $newPostsArray,
|
|
||||||
# $responseJson
|
|
||||||
#);
|
|
||||||
|
|
||||||
$this->validatePostsObject($responseJson['Posts']);
|
|
||||||
$this->waypoint("Validate Object Response");
|
|
||||||
//TODO: Make this respect primary key field instead of assuming ID.
|
|
||||||
if(!isset($responseJson['Posts']['Id'])){
|
|
||||||
$this->markTestIncomplete("Skipped test... Posts response object doesn't have an ID field.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $responseJson['Posts']['Id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function testPostsCreateFails()
|
|
||||||
{
|
|
||||||
$this->waypoint("Begin");
|
|
||||||
|
|
||||||
$newPosts = [
|
|
||||||
'id' => null,
|
|
||||||
'title' => null,
|
|
||||||
'content' => null,
|
|
||||||
'authorId' => null,
|
|
||||||
'createdDate' => null,
|
|
||||||
'publishedDate' => null,
|
|
||||||
'deleted' => null,
|
|
||||||
];
|
|
||||||
$response = $this->request("PUT", "/v1/posts", $newPosts);
|
|
||||||
$this->waypoint("API PUT REST REQUEST");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
$this->assertTrue(in_array($response->getStatusCode(), [200,400]), "Response was not expected 200 or 400. Response body is: \n\n" . $body . "\n\n"); $this->waypoint("Get & Parse Response");
|
|
||||||
$this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\" Request JSON blob: \"" . json_encode($newPosts) . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode((string)$body, true);
|
|
||||||
$this->waypoint("JSON DECODE");
|
|
||||||
$this->assertArrayHasKey('Status', $responseJson);
|
|
||||||
$this->assertEquals("Fail", $responseJson['Status'], "Object was created, when failure was expected.");
|
|
||||||
$this->waypoint("Some assertions");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testPostsCreate
|
|
||||||
*/
|
|
||||||
public function testPostsGet($id)
|
|
||||||
{
|
|
||||||
$this->waypoint("Begin");
|
|
||||||
$response = $this->request("GET", "/v1/posts/{$id}");
|
|
||||||
$this->waypoint("API GET REST REQUEST");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
$this->assertTrue(in_array($response->getStatusCode(), [200,400]), "Response was not expected 200 or 400. Response body is: \n\n" . $body . "\n\n"); $this->waypoint("Get & Parse Response");
|
|
||||||
$this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode((string)$body, true);
|
|
||||||
$this->waypoint("JSON DECODE");
|
|
||||||
$this->assertArrayHasKey('Status', $responseJson);
|
|
||||||
$this->assertEquals("Okay", $responseJson['Status'], "Verify that request to GET /v1/posts/{$id} returns an \"Status: Okay\" response. This failed. " . (isset($responseJson['Reason']) ? "Reason: " . $responseJson['Reason'] : "No Reason Given"));
|
|
||||||
$this->assertArrayHasKey('Posts', $responseJson);
|
|
||||||
$this->waypoint("Some assertions");
|
|
||||||
|
|
||||||
$this->validatePostsObject($responseJson['Posts']);
|
|
||||||
$this->waypoint("Validate Object Response");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testPostsCreate
|
|
||||||
*/
|
|
||||||
public function testPostsList()
|
|
||||||
{
|
|
||||||
$this->waypoint("Begin");
|
|
||||||
$response = $this->request("GET", "/v1/posts");
|
|
||||||
$this->waypoint("API REST REQUEST");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
$this->assertTrue(in_array($response->getStatusCode(), [200,400]), "Response was not expected 200 or 400. Response body is: \n\n" . $body . "\n\n"); $this->waypoint("Get & Parse Response");
|
|
||||||
$this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode((string)$body, true);
|
|
||||||
$this->waypoint("JSON DECODE");
|
|
||||||
$this->assertArrayHasKey('Status', $responseJson);
|
|
||||||
$this->assertEquals("Okay", $responseJson['Status'], "Verify that request to GET /v1/posts returns an \"Status: Okay\" response. This failed. " . (isset($responseJson['Reason']) ? "Reason: " . $responseJson['Reason'] : "No Reason Given"));
|
|
||||||
$this->assertArrayHasKey('Posts', $responseJson);
|
|
||||||
$this->waypoint("Some assertions");
|
|
||||||
$this->validatePostsObject(reset($responseJson['Posts']));
|
|
||||||
$this->waypoint("Validate Object Response");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testPostsCreate
|
|
||||||
*/
|
|
||||||
public function testPostsDelete($id)
|
|
||||||
{
|
|
||||||
$response = $this->request("DELETE", "/v1/posts/{$id}");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
$this->assertTrue(in_array($response->getStatusCode(), [200,400]), "Response was not expected 200 or 400. Response body is: \n\n" . $body . "\n\n"); $this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode((string)$body, true);
|
|
||||||
$this->assertArrayHasKey('Status', $responseJson);
|
|
||||||
$this->assertEquals("Okay", $responseJson['Status'], "Verify that request to DELETE /v1/posts/{$id} returns an \"Status: Okay\" response. This failed. " . (isset($responseJson['Reason']) ? "Reason: " . $responseJson['Reason'] : "No Reason Given"));
|
|
||||||
$this->assertEquals("DELETE", $responseJson['Action']);
|
|
||||||
$this->assertArrayHasKey('Posts', $responseJson);
|
|
||||||
$this->validatePostsObject($responseJson['Posts']);
|
|
||||||
return $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testPostsDelete
|
|
||||||
*/
|
|
||||||
public function testPostsDeleteVerify($id)
|
|
||||||
{
|
|
||||||
$response = $this->request("GET", "/v1/posts/{$id}");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
$this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode((string)$body, true);
|
|
||||||
$this->assertEquals("Fail", $responseJson['Status']);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function validatePostsObject($PostsObject)
|
|
||||||
{
|
|
||||||
$this->assertArrayHasKey('Id', $PostsObject, "There was no element with the key 'id'.");
|
|
||||||
$this->assertArrayHasKey('Title', $PostsObject, "There was no element with the key 'title'.");
|
|
||||||
$this->assertArrayHasKey('Content', $PostsObject, "There was no element with the key 'content'.");
|
|
||||||
$this->assertArrayHasKey('AuthorId', $PostsObject, "There was no element with the key 'authorId'.");
|
|
||||||
$this->assertArrayHasKey('CreatedDate', $PostsObject, "There was no element with the key 'createdDate'.");
|
|
||||||
$this->assertArrayHasKey('PublishedDate', $PostsObject, "There was no element with the key 'publishedDate'.");
|
|
||||||
$this->assertArrayHasKey('Deleted', $PostsObject, "There was no element with the key 'deleted'.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,207 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Example\BlogApp\Test\Api\Generated;
|
|
||||||
|
|
||||||
use Example\BlogApp\TableGateways;
|
|
||||||
use Example\BlogApp\Models\UsersModel;
|
|
||||||
use Example\BlogApp\Services\UsersService;
|
|
||||||
use ⌬\Tests\RoutesTestCase;
|
|
||||||
|
|
||||||
class UsersEndpointTest extends RoutesTestCase
|
|
||||||
{
|
|
||||||
|
|
||||||
const MODEL_NAME = 'Users';
|
|
||||||
|
|
||||||
public function testUsersCreate()
|
|
||||||
{
|
|
||||||
$this->waypoint("Begin");
|
|
||||||
/** @var UsersService $service */
|
|
||||||
$service = $this->getApp()->getContainer()->get(UsersService::class);
|
|
||||||
/** @var UsersModel $newUsers **/
|
|
||||||
$newUsers = $service->getMockObject();
|
|
||||||
|
|
||||||
$this->waypoint("Initialise Mock Model");
|
|
||||||
$newUsersArray = $newUsers->__toArray();
|
|
||||||
|
|
||||||
$method = "PUT";
|
|
||||||
$uri = "/v1/users";
|
|
||||||
|
|
||||||
$response = $this->request(
|
|
||||||
$method,
|
|
||||||
$uri,
|
|
||||||
$newUsersArray
|
|
||||||
);
|
|
||||||
$this->waypoint("API PUT REST REQUEST");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
\Kint::dump(
|
|
||||||
$newUsersArray,
|
|
||||||
json_encode($newUsersArray, JSON_PRETTY_PRINT)
|
|
||||||
);
|
|
||||||
$requestUsersParams = ob_get_contents();
|
|
||||||
ob_end_clean();
|
|
||||||
|
|
||||||
$this->assertTrue(
|
|
||||||
in_array(
|
|
||||||
$response->getStatusCode(),
|
|
||||||
[
|
|
||||||
200,
|
|
||||||
400,
|
|
||||||
]
|
|
||||||
),
|
|
||||||
"Response was not expected 200 or 400.\n" .
|
|
||||||
"Request: {$method} => {$uri}" .
|
|
||||||
"{$requestUsersParams}\n" .
|
|
||||||
"Response body is: \n" .
|
|
||||||
" ******************************\n{$body}\n ******************************\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->waypoint("Get & Parse Response");
|
|
||||||
$this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\" Request JSON blob: \"" . json_encode($newUsers->__toArray()) . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode($body, true);
|
|
||||||
$this->waypoint("JSON DECODE");
|
|
||||||
$this->assertArrayHasKey('Status', $responseJson);
|
|
||||||
$this->assertEquals("Okay", $responseJson['Status'], "Verify that request to PUT /v1/users returns an \"Status: Okay\" response. This failed. " . (isset($responseJson['Reason']) ? "Reason: " . $responseJson['Reason'] : "No Reason Given"));
|
|
||||||
$this->assertArrayHasKey('Users', $responseJson);
|
|
||||||
$this->waypoint("Some assertions");
|
|
||||||
|
|
||||||
#\Kint::dump(
|
|
||||||
# $newUsersArray,
|
|
||||||
# $responseJson
|
|
||||||
#);
|
|
||||||
|
|
||||||
$this->validateUsersObject($responseJson['Users']);
|
|
||||||
$this->waypoint("Validate Object Response");
|
|
||||||
//TODO: Make this respect primary key field instead of assuming ID.
|
|
||||||
if(!isset($responseJson['Users']['Id'])){
|
|
||||||
$this->markTestIncomplete("Skipped test... Users response object doesn't have an ID field.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $responseJson['Users']['Id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function testUsersCreateFails()
|
|
||||||
{
|
|
||||||
$this->waypoint("Begin");
|
|
||||||
|
|
||||||
$newUsers = [
|
|
||||||
'id' => null,
|
|
||||||
'displayName' => null,
|
|
||||||
'userName' => null,
|
|
||||||
'email' => null,
|
|
||||||
'password' => null,
|
|
||||||
];
|
|
||||||
$response = $this->request("PUT", "/v1/users", $newUsers);
|
|
||||||
$this->waypoint("API PUT REST REQUEST");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
$this->assertTrue(in_array($response->getStatusCode(), [200,400]), "Response was not expected 200 or 400. Response body is: \n\n" . $body . "\n\n"); $this->waypoint("Get & Parse Response");
|
|
||||||
$this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\" Request JSON blob: \"" . json_encode($newUsers) . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode((string)$body, true);
|
|
||||||
$this->waypoint("JSON DECODE");
|
|
||||||
$this->assertArrayHasKey('Status', $responseJson);
|
|
||||||
$this->assertEquals("Fail", $responseJson['Status'], "Object was created, when failure was expected.");
|
|
||||||
$this->waypoint("Some assertions");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testUsersCreate
|
|
||||||
*/
|
|
||||||
public function testUsersGet($id)
|
|
||||||
{
|
|
||||||
$this->waypoint("Begin");
|
|
||||||
$response = $this->request("GET", "/v1/users/{$id}");
|
|
||||||
$this->waypoint("API GET REST REQUEST");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
$this->assertTrue(in_array($response->getStatusCode(), [200,400]), "Response was not expected 200 or 400. Response body is: \n\n" . $body . "\n\n"); $this->waypoint("Get & Parse Response");
|
|
||||||
$this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode((string)$body, true);
|
|
||||||
$this->waypoint("JSON DECODE");
|
|
||||||
$this->assertArrayHasKey('Status', $responseJson);
|
|
||||||
$this->assertEquals("Okay", $responseJson['Status'], "Verify that request to GET /v1/users/{$id} returns an \"Status: Okay\" response. This failed. " . (isset($responseJson['Reason']) ? "Reason: " . $responseJson['Reason'] : "No Reason Given"));
|
|
||||||
$this->assertArrayHasKey('Users', $responseJson);
|
|
||||||
$this->waypoint("Some assertions");
|
|
||||||
|
|
||||||
$this->validateUsersObject($responseJson['Users']);
|
|
||||||
$this->waypoint("Validate Object Response");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testUsersCreate
|
|
||||||
*/
|
|
||||||
public function testUsersList()
|
|
||||||
{
|
|
||||||
$this->waypoint("Begin");
|
|
||||||
$response = $this->request("GET", "/v1/users");
|
|
||||||
$this->waypoint("API REST REQUEST");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
$this->assertTrue(in_array($response->getStatusCode(), [200,400]), "Response was not expected 200 or 400. Response body is: \n\n" . $body . "\n\n"); $this->waypoint("Get & Parse Response");
|
|
||||||
$this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode((string)$body, true);
|
|
||||||
$this->waypoint("JSON DECODE");
|
|
||||||
$this->assertArrayHasKey('Status', $responseJson);
|
|
||||||
$this->assertEquals("Okay", $responseJson['Status'], "Verify that request to GET /v1/users returns an \"Status: Okay\" response. This failed. " . (isset($responseJson['Reason']) ? "Reason: " . $responseJson['Reason'] : "No Reason Given"));
|
|
||||||
$this->assertArrayHasKey('Users', $responseJson);
|
|
||||||
$this->waypoint("Some assertions");
|
|
||||||
$this->validateUsersObject(reset($responseJson['Users']));
|
|
||||||
$this->waypoint("Validate Object Response");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testUsersCreate
|
|
||||||
*/
|
|
||||||
public function testUsersDelete($id)
|
|
||||||
{
|
|
||||||
$response = $this->request("DELETE", "/v1/users/{$id}");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
$this->assertTrue(in_array($response->getStatusCode(), [200,400]), "Response was not expected 200 or 400. Response body is: \n\n" . $body . "\n\n"); $this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode((string)$body, true);
|
|
||||||
$this->assertArrayHasKey('Status', $responseJson);
|
|
||||||
$this->assertEquals("Okay", $responseJson['Status'], "Verify that request to DELETE /v1/users/{$id} returns an \"Status: Okay\" response. This failed. " . (isset($responseJson['Reason']) ? "Reason: " . $responseJson['Reason'] : "No Reason Given"));
|
|
||||||
$this->assertEquals("DELETE", $responseJson['Action']);
|
|
||||||
$this->assertArrayHasKey('Users', $responseJson);
|
|
||||||
$this->validateUsersObject($responseJson['Users']);
|
|
||||||
return $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testUsersDelete
|
|
||||||
*/
|
|
||||||
public function testUsersDeleteVerify($id)
|
|
||||||
{
|
|
||||||
$response = $this->request("GET", "/v1/users/{$id}");
|
|
||||||
$body = (string) $response->getBody();
|
|
||||||
$this->assertNotNull(
|
|
||||||
json_decode((string) $body),
|
|
||||||
"Assert that the JSON response is actually JSON that is parsable failed. Response was: \"". (string) $body . "\""
|
|
||||||
);
|
|
||||||
$responseJson = json_decode((string)$body, true);
|
|
||||||
$this->assertEquals("Fail", $responseJson['Status']);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function validateUsersObject($UsersObject)
|
|
||||||
{
|
|
||||||
$this->assertArrayHasKey('Id', $UsersObject, "There was no element with the key 'id'.");
|
|
||||||
$this->assertArrayHasKey('DisplayName', $UsersObject, "There was no element with the key 'displayName'.");
|
|
||||||
$this->assertArrayHasKey('UserName', $UsersObject, "There was no element with the key 'userName'.");
|
|
||||||
$this->assertArrayHasKey('Email', $UsersObject, "There was no element with the key 'email'.");
|
|
||||||
$this->assertArrayHasKey('Password', $UsersObject, "There was no element with the key 'password'.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,215 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Test\Models\Generated;
|
|
||||||
|
|
||||||
use \Example\BlogApp\TableGateways;
|
|
||||||
use \Example\BlogApp\TableGateways\CommentsTableGateway;
|
|
||||||
use \Example\BlogApp\Models\CommentsModel;
|
|
||||||
use \Example\BlogApp\Models;
|
|
||||||
use \Gone\UUID\UUID;
|
|
||||||
use ⌬\Tests\BaseTestCase;
|
|
||||||
|
|
||||||
|
|
||||||
class CommentsTest extends BaseTestCase
|
|
||||||
{
|
|
||||||
/** @var CommentsTableGateway */
|
|
||||||
protected $testTableGateway;
|
|
||||||
|
|
||||||
/** @var CommentsModel */
|
|
||||||
protected $testInstance;
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
$this->testTableGateway = $this->getDIContainer()->get(CommentsTableGateway::class);
|
|
||||||
$this->testInstance = $this->testTableGateway->getNewMockModelInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testExchangeArray()
|
|
||||||
{
|
|
||||||
$data = [];
|
|
||||||
$data['id'] = self::getFaker()->randomDigitNotNull;
|
|
||||||
$data['comment'] = self::getFaker()->word;
|
|
||||||
$data['authorId'] = self::getFaker()->randomDigitNotNull;
|
|
||||||
$data['publishedDate'] = self::getFaker()->word;
|
|
||||||
$this->testInstance = new CommentsModel($data);
|
|
||||||
$this->assertEquals($data['id'], $this->testInstance->getId());
|
|
||||||
$this->assertEquals($data['comment'], $this->testInstance->getComment());
|
|
||||||
$this->assertEquals($data['authorId'], $this->testInstance->getAuthorId());
|
|
||||||
$this->assertEquals($data['publishedDate'], $this->testInstance->getPublishedDate());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetRandom()
|
|
||||||
{
|
|
||||||
/** @var CommentsTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(CommentsTableGateway::class);
|
|
||||||
|
|
||||||
// If there is no data in the table, create some.
|
|
||||||
if($table->getCount() == 0){
|
|
||||||
$dummyObject = $table->getNewMockModelInstance();
|
|
||||||
$table->save($dummyObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
$comment = $table->fetchRandom();
|
|
||||||
$this->assertTrue($comment instanceof CommentsModel, "Make sure that \"" . get_class($comment) . "\" matches \"CommentsModel\"") ;
|
|
||||||
|
|
||||||
return $comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testNewMockModelInstance()
|
|
||||||
{
|
|
||||||
/** @var CommentsTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(CommentsTableGateway::class);
|
|
||||||
$new = $table->getNewMockModelInstance();
|
|
||||||
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
Models\CommentsModel::class,
|
|
||||||
$new
|
|
||||||
);
|
|
||||||
|
|
||||||
$new->save();
|
|
||||||
|
|
||||||
return $new;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testNewModelFactory()
|
|
||||||
{
|
|
||||||
$instance = CommentsModel::factory();
|
|
||||||
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
Models\CommentsModel::class,
|
|
||||||
$instance
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSave()
|
|
||||||
{
|
|
||||||
/** @var CommentsTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(CommentsTableGateway::class);
|
|
||||||
/** @var Models\CommentsModel $mockModel */
|
|
||||||
/** @var Models\CommentsModel $savedModel */
|
|
||||||
$mockModel = $table->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]);
|
|
||||||
unset($savedModelArray[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$this->assertEquals($mockModelArray, $savedModelArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetById(CommentsModel $comments)
|
|
||||||
{
|
|
||||||
/** @var commentsTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(CommentsTableGateway::class);
|
|
||||||
$results = $table->select(['id' => $comments->getId()]);
|
|
||||||
$commentsRow = $results->current();
|
|
||||||
$this->assertTrue($commentsRow instanceof CommentsModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testSettersAndGetters(CommentsModel $comments)
|
|
||||||
{
|
|
||||||
$this->assertTrue(method_exists($comments, "getid"));
|
|
||||||
$this->assertTrue(method_exists($comments, "setid"));
|
|
||||||
$this->assertTrue(method_exists($comments, "getcomment"));
|
|
||||||
$this->assertTrue(method_exists($comments, "setcomment"));
|
|
||||||
$this->assertTrue(method_exists($comments, "getauthorId"));
|
|
||||||
$this->assertTrue(method_exists($comments, "setauthorId"));
|
|
||||||
$this->assertTrue(method_exists($comments, "getpublishedDate"));
|
|
||||||
$this->assertTrue(method_exists($comments, "setpublishedDate"));
|
|
||||||
|
|
||||||
$testComments = new CommentsModel();
|
|
||||||
$input = self::getFaker()->randomDigitNotNull;
|
|
||||||
$testComments->setId($input);
|
|
||||||
$this->assertEquals($input, $testComments->getid());
|
|
||||||
$input = self::getFaker()->word;
|
|
||||||
$testComments->setComment($input);
|
|
||||||
$this->assertEquals($input, $testComments->getcomment());
|
|
||||||
$input = self::getFaker()->randomDigitNotNull;
|
|
||||||
$testComments->setAuthorId($input);
|
|
||||||
$this->assertEquals($input, $testComments->getauthorId());
|
|
||||||
$input = self::getFaker()->word;
|
|
||||||
$testComments->setPublishedDate($input);
|
|
||||||
$this->assertEquals($input, $testComments->getpublishedDate());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function testAutoincrementedIdIsApplied()
|
|
||||||
{
|
|
||||||
/** @var CommentsTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(CommentsTableGateway::class);
|
|
||||||
$new = $table->getNewMockModelInstance();
|
|
||||||
|
|
||||||
// Set primary keys to null.
|
|
||||||
$new->setid(null);
|
|
||||||
|
|
||||||
// Save the object
|
|
||||||
$new->save();
|
|
||||||
|
|
||||||
// verify that the AI keys have been set.
|
|
||||||
$this->assertNotNull($new->getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDestroy()
|
|
||||||
{
|
|
||||||
/** @var CommentsTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(CommentsTableGateway::class);
|
|
||||||
/** @var Models\CommentsModel $destroyableModel */
|
|
||||||
$destroyableModel = $table->getNewMockModelInstance();
|
|
||||||
$destroyableModel->save();
|
|
||||||
$this->assertTrue(true, $destroyableModel->destroy());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDestroyThoroughly()
|
|
||||||
{
|
|
||||||
/** @var CommentsTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(CommentsTableGateway::class);
|
|
||||||
/** @var Models\CommentsModel $destroyableModel */
|
|
||||||
$destroyableModel = $table->getNewMockModelInstance();
|
|
||||||
$destroyableModel->save();
|
|
||||||
$this->assertGreaterThan(0, $destroyableModel->destroyThoroughly());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testNewMockModelInstance
|
|
||||||
*/
|
|
||||||
public function test_RelatedObjects_FetchUserObject(CommentsModel $comment)
|
|
||||||
{
|
|
||||||
// Verify the function exists
|
|
||||||
$this->assertTrue(method_exists($comment, "fetchUserObject"));
|
|
||||||
|
|
||||||
// Call the function on it
|
|
||||||
$commentModel = $comment->fetchUserObject();
|
|
||||||
|
|
||||||
$this->assertInstanceOf(Models\UsersModel::class, $commentModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function testGetPropertyMeta()
|
|
||||||
{
|
|
||||||
$propertyMeta = $this->testInstance->getPropertyMeta();
|
|
||||||
$this->assertTrue(is_array($propertyMeta));
|
|
||||||
$this->assertGreaterThan(0, count($propertyMeta));
|
|
||||||
$this->assertArrayHasKey('id', $propertyMeta);
|
|
||||||
$this->assertArrayHasKey('comment', $propertyMeta);
|
|
||||||
$this->assertArrayHasKey('authorId', $propertyMeta);
|
|
||||||
$this->assertArrayHasKey('publishedDate', $propertyMeta);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,239 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Test\Models\Generated;
|
|
||||||
|
|
||||||
use \Example\BlogApp\TableGateways;
|
|
||||||
use \Example\BlogApp\TableGateways\PostsTableGateway;
|
|
||||||
use \Example\BlogApp\Models\PostsModel;
|
|
||||||
use \Example\BlogApp\Models;
|
|
||||||
use \Gone\UUID\UUID;
|
|
||||||
use ⌬\Tests\BaseTestCase;
|
|
||||||
|
|
||||||
|
|
||||||
class PostsTest extends BaseTestCase
|
|
||||||
{
|
|
||||||
/** @var PostsTableGateway */
|
|
||||||
protected $testTableGateway;
|
|
||||||
|
|
||||||
/** @var PostsModel */
|
|
||||||
protected $testInstance;
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
$this->testTableGateway = $this->getDIContainer()->get(PostsTableGateway::class);
|
|
||||||
$this->testInstance = $this->testTableGateway->getNewMockModelInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testExchangeArray()
|
|
||||||
{
|
|
||||||
$data = [];
|
|
||||||
$data['id'] = self::getFaker()->randomDigitNotNull;
|
|
||||||
$data['title'] = self::getFaker()->word;
|
|
||||||
$data['content'] = self::getFaker()->word;
|
|
||||||
$data['authorId'] = self::getFaker()->randomDigitNotNull;
|
|
||||||
$data['createdDate'] = self::getFaker()->word;
|
|
||||||
$data['publishedDate'] = self::getFaker()->word;
|
|
||||||
$data['deleted'] = self::getFaker()->word;
|
|
||||||
$this->testInstance = new PostsModel($data);
|
|
||||||
$this->assertEquals($data['id'], $this->testInstance->getId());
|
|
||||||
$this->assertEquals($data['title'], $this->testInstance->getTitle());
|
|
||||||
$this->assertEquals($data['content'], $this->testInstance->getContent());
|
|
||||||
$this->assertEquals($data['authorId'], $this->testInstance->getAuthorId());
|
|
||||||
$this->assertEquals($data['createdDate'], $this->testInstance->getCreatedDate());
|
|
||||||
$this->assertEquals($data['publishedDate'], $this->testInstance->getPublishedDate());
|
|
||||||
$this->assertEquals($data['deleted'], $this->testInstance->getDeleted());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetRandom()
|
|
||||||
{
|
|
||||||
/** @var PostsTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(PostsTableGateway::class);
|
|
||||||
|
|
||||||
// If there is no data in the table, create some.
|
|
||||||
if($table->getCount() == 0){
|
|
||||||
$dummyObject = $table->getNewMockModelInstance();
|
|
||||||
$table->save($dummyObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
$post = $table->fetchRandom();
|
|
||||||
$this->assertTrue($post instanceof PostsModel, "Make sure that \"" . get_class($post) . "\" matches \"PostsModel\"") ;
|
|
||||||
|
|
||||||
return $post;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testNewMockModelInstance()
|
|
||||||
{
|
|
||||||
/** @var PostsTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(PostsTableGateway::class);
|
|
||||||
$new = $table->getNewMockModelInstance();
|
|
||||||
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
Models\PostsModel::class,
|
|
||||||
$new
|
|
||||||
);
|
|
||||||
|
|
||||||
$new->save();
|
|
||||||
|
|
||||||
return $new;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testNewModelFactory()
|
|
||||||
{
|
|
||||||
$instance = PostsModel::factory();
|
|
||||||
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
Models\PostsModel::class,
|
|
||||||
$instance
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSave()
|
|
||||||
{
|
|
||||||
/** @var PostsTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(PostsTableGateway::class);
|
|
||||||
/** @var Models\PostsModel $mockModel */
|
|
||||||
/** @var Models\PostsModel $savedModel */
|
|
||||||
$mockModel = $table->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]);
|
|
||||||
unset($savedModelArray[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$this->assertEquals($mockModelArray, $savedModelArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetById(PostsModel $posts)
|
|
||||||
{
|
|
||||||
/** @var postsTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(PostsTableGateway::class);
|
|
||||||
$results = $table->select(['id' => $posts->getId()]);
|
|
||||||
$postsRow = $results->current();
|
|
||||||
$this->assertTrue($postsRow instanceof PostsModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testSettersAndGetters(PostsModel $posts)
|
|
||||||
{
|
|
||||||
$this->assertTrue(method_exists($posts, "getid"));
|
|
||||||
$this->assertTrue(method_exists($posts, "setid"));
|
|
||||||
$this->assertTrue(method_exists($posts, "gettitle"));
|
|
||||||
$this->assertTrue(method_exists($posts, "settitle"));
|
|
||||||
$this->assertTrue(method_exists($posts, "getcontent"));
|
|
||||||
$this->assertTrue(method_exists($posts, "setcontent"));
|
|
||||||
$this->assertTrue(method_exists($posts, "getauthorId"));
|
|
||||||
$this->assertTrue(method_exists($posts, "setauthorId"));
|
|
||||||
$this->assertTrue(method_exists($posts, "getcreatedDate"));
|
|
||||||
$this->assertTrue(method_exists($posts, "setcreatedDate"));
|
|
||||||
$this->assertTrue(method_exists($posts, "getpublishedDate"));
|
|
||||||
$this->assertTrue(method_exists($posts, "setpublishedDate"));
|
|
||||||
$this->assertTrue(method_exists($posts, "getdeleted"));
|
|
||||||
$this->assertTrue(method_exists($posts, "setdeleted"));
|
|
||||||
|
|
||||||
$testPosts = new PostsModel();
|
|
||||||
$input = self::getFaker()->randomDigitNotNull;
|
|
||||||
$testPosts->setId($input);
|
|
||||||
$this->assertEquals($input, $testPosts->getid());
|
|
||||||
$input = self::getFaker()->word;
|
|
||||||
$testPosts->setTitle($input);
|
|
||||||
$this->assertEquals($input, $testPosts->gettitle());
|
|
||||||
$input = self::getFaker()->word;
|
|
||||||
$testPosts->setContent($input);
|
|
||||||
$this->assertEquals($input, $testPosts->getcontent());
|
|
||||||
$input = self::getFaker()->randomDigitNotNull;
|
|
||||||
$testPosts->setAuthorId($input);
|
|
||||||
$this->assertEquals($input, $testPosts->getauthorId());
|
|
||||||
$input = self::getFaker()->word;
|
|
||||||
$testPosts->setCreatedDate($input);
|
|
||||||
$this->assertEquals($input, $testPosts->getcreatedDate());
|
|
||||||
$input = self::getFaker()->word;
|
|
||||||
$testPosts->setPublishedDate($input);
|
|
||||||
$this->assertEquals($input, $testPosts->getpublishedDate());
|
|
||||||
$input = self::getFaker()->word;
|
|
||||||
$testPosts->setDeleted($input);
|
|
||||||
$this->assertEquals($input, $testPosts->getdeleted());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function testAutoincrementedIdIsApplied()
|
|
||||||
{
|
|
||||||
/** @var PostsTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(PostsTableGateway::class);
|
|
||||||
$new = $table->getNewMockModelInstance();
|
|
||||||
|
|
||||||
// Set primary keys to null.
|
|
||||||
$new->setid(null);
|
|
||||||
|
|
||||||
// Save the object
|
|
||||||
$new->save();
|
|
||||||
|
|
||||||
// verify that the AI keys have been set.
|
|
||||||
$this->assertNotNull($new->getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDestroy()
|
|
||||||
{
|
|
||||||
/** @var PostsTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(PostsTableGateway::class);
|
|
||||||
/** @var Models\PostsModel $destroyableModel */
|
|
||||||
$destroyableModel = $table->getNewMockModelInstance();
|
|
||||||
$destroyableModel->save();
|
|
||||||
$this->assertTrue(true, $destroyableModel->destroy());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDestroyThoroughly()
|
|
||||||
{
|
|
||||||
/** @var PostsTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(PostsTableGateway::class);
|
|
||||||
/** @var Models\PostsModel $destroyableModel */
|
|
||||||
$destroyableModel = $table->getNewMockModelInstance();
|
|
||||||
$destroyableModel->save();
|
|
||||||
$this->assertGreaterThan(0, $destroyableModel->destroyThoroughly());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testNewMockModelInstance
|
|
||||||
*/
|
|
||||||
public function test_RelatedObjects_FetchUserObject(PostsModel $post)
|
|
||||||
{
|
|
||||||
// Verify the function exists
|
|
||||||
$this->assertTrue(method_exists($post, "fetchUserObject"));
|
|
||||||
|
|
||||||
// Call the function on it
|
|
||||||
$postModel = $post->fetchUserObject();
|
|
||||||
|
|
||||||
$this->assertInstanceOf(Models\UsersModel::class, $postModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function testGetPropertyMeta()
|
|
||||||
{
|
|
||||||
$propertyMeta = $this->testInstance->getPropertyMeta();
|
|
||||||
$this->assertTrue(is_array($propertyMeta));
|
|
||||||
$this->assertGreaterThan(0, count($propertyMeta));
|
|
||||||
$this->assertArrayHasKey('id', $propertyMeta);
|
|
||||||
$this->assertArrayHasKey('title', $propertyMeta);
|
|
||||||
$this->assertArrayHasKey('content', $propertyMeta);
|
|
||||||
$this->assertArrayHasKey('authorId', $propertyMeta);
|
|
||||||
$this->assertArrayHasKey('createdDate', $propertyMeta);
|
|
||||||
$this->assertArrayHasKey('publishedDate', $propertyMeta);
|
|
||||||
$this->assertArrayHasKey('deleted', $propertyMeta);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,344 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Test\Models\Generated;
|
|
||||||
|
|
||||||
use \Example\BlogApp\TableGateways;
|
|
||||||
use \Example\BlogApp\TableGateways\UsersTableGateway;
|
|
||||||
use \Example\BlogApp\Models\UsersModel;
|
|
||||||
use \Example\BlogApp\Models;
|
|
||||||
use \Gone\UUID\UUID;
|
|
||||||
use ⌬\Tests\BaseTestCase;
|
|
||||||
|
|
||||||
|
|
||||||
class UsersTest extends BaseTestCase
|
|
||||||
{
|
|
||||||
/** @var UsersTableGateway */
|
|
||||||
protected $testTableGateway;
|
|
||||||
|
|
||||||
/** @var UsersModel */
|
|
||||||
protected $testInstance;
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
$this->testTableGateway = $this->getDIContainer()->get(UsersTableGateway::class);
|
|
||||||
$this->testInstance = $this->testTableGateway->getNewMockModelInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testExchangeArray()
|
|
||||||
{
|
|
||||||
$data = [];
|
|
||||||
$data['id'] = self::getFaker()->randomDigitNotNull;
|
|
||||||
$data['displayName'] = self::getFaker()->word;
|
|
||||||
$data['userName'] = self::getFaker()->word;
|
|
||||||
$data['email'] = self::getFaker()->word;
|
|
||||||
$data['password'] = self::getFaker()->word;
|
|
||||||
$this->testInstance = new UsersModel($data);
|
|
||||||
$this->assertEquals($data['id'], $this->testInstance->getId());
|
|
||||||
$this->assertEquals($data['displayName'], $this->testInstance->getDisplayName());
|
|
||||||
$this->assertEquals($data['userName'], $this->testInstance->getUserName());
|
|
||||||
$this->assertEquals($data['email'], $this->testInstance->getEmail());
|
|
||||||
$this->assertEquals($data['password'], $this->testInstance->getPassword());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetRandom()
|
|
||||||
{
|
|
||||||
/** @var UsersTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(UsersTableGateway::class);
|
|
||||||
|
|
||||||
// If there is no data in the table, create some.
|
|
||||||
if($table->getCount() == 0){
|
|
||||||
$dummyObject = $table->getNewMockModelInstance();
|
|
||||||
$table->save($dummyObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = $table->fetchRandom();
|
|
||||||
$this->assertTrue($user instanceof UsersModel, "Make sure that \"" . get_class($user) . "\" matches \"UsersModel\"") ;
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testNewMockModelInstance()
|
|
||||||
{
|
|
||||||
/** @var UsersTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(UsersTableGateway::class);
|
|
||||||
$new = $table->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 UsersTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(UsersTableGateway::class);
|
|
||||||
/** @var Models\UsersModel $mockModel */
|
|
||||||
/** @var Models\UsersModel $savedModel */
|
|
||||||
$mockModel = $table->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]);
|
|
||||||
unset($savedModelArray[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$this->assertEquals($mockModelArray, $savedModelArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetById(UsersModel $users)
|
|
||||||
{
|
|
||||||
/** @var usersTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(UsersTableGateway::class);
|
|
||||||
$results = $table->select(['id' => $users->getId()]);
|
|
||||||
$usersRow = $results->current();
|
|
||||||
$this->assertTrue($usersRow instanceof UsersModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testSettersAndGetters(UsersModel $users)
|
|
||||||
{
|
|
||||||
$this->assertTrue(method_exists($users, "getid"));
|
|
||||||
$this->assertTrue(method_exists($users, "setid"));
|
|
||||||
$this->assertTrue(method_exists($users, "getdisplayName"));
|
|
||||||
$this->assertTrue(method_exists($users, "setdisplayName"));
|
|
||||||
$this->assertTrue(method_exists($users, "getuserName"));
|
|
||||||
$this->assertTrue(method_exists($users, "setuserName"));
|
|
||||||
$this->assertTrue(method_exists($users, "getemail"));
|
|
||||||
$this->assertTrue(method_exists($users, "setemail"));
|
|
||||||
$this->assertTrue(method_exists($users, "getpassword"));
|
|
||||||
$this->assertTrue(method_exists($users, "setpassword"));
|
|
||||||
|
|
||||||
$testUsers = new UsersModel();
|
|
||||||
$input = self::getFaker()->randomDigitNotNull;
|
|
||||||
$testUsers->setId($input);
|
|
||||||
$this->assertEquals($input, $testUsers->getid());
|
|
||||||
$input = self::getFaker()->word;
|
|
||||||
$testUsers->setDisplayName($input);
|
|
||||||
$this->assertEquals($input, $testUsers->getdisplayName());
|
|
||||||
$input = self::getFaker()->word;
|
|
||||||
$testUsers->setUserName($input);
|
|
||||||
$this->assertEquals($input, $testUsers->getuserName());
|
|
||||||
$input = self::getFaker()->word;
|
|
||||||
$testUsers->setEmail($input);
|
|
||||||
$this->assertEquals($input, $testUsers->getemail());
|
|
||||||
$input = self::getFaker()->word;
|
|
||||||
$testUsers->setPassword($input);
|
|
||||||
$this->assertEquals($input, $testUsers->getpassword());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function testAutoincrementedIdIsApplied()
|
|
||||||
{
|
|
||||||
/** @var UsersTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(UsersTableGateway::class);
|
|
||||||
$new = $table->getNewMockModelInstance();
|
|
||||||
|
|
||||||
// Set primary keys to null.
|
|
||||||
$new->setid(null);
|
|
||||||
|
|
||||||
// Save the object
|
|
||||||
$new->save();
|
|
||||||
|
|
||||||
// verify that the AI keys have been set.
|
|
||||||
$this->assertNotNull($new->getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDestroy()
|
|
||||||
{
|
|
||||||
/** @var UsersTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(UsersTableGateway::class);
|
|
||||||
/** @var Models\UsersModel $destroyableModel */
|
|
||||||
$destroyableModel = $table->getNewMockModelInstance();
|
|
||||||
$destroyableModel->save();
|
|
||||||
$this->assertTrue(true, $destroyableModel->destroy());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDestroyThoroughly()
|
|
||||||
{
|
|
||||||
/** @var UsersTableGateway $table */
|
|
||||||
$table = $this->getDIContainer()->get(UsersTableGateway::class);
|
|
||||||
/** @var Models\UsersModel $destroyableModel */
|
|
||||||
$destroyableModel = $table->getNewMockModelInstance();
|
|
||||||
$destroyableModel->save();
|
|
||||||
$this->assertGreaterThan(0, $destroyableModel->destroyThoroughly());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testNewMockModelInstance
|
|
||||||
*/
|
|
||||||
public function test_RemoteObjects_FetchPostObjects(UsersModel $user)
|
|
||||||
{
|
|
||||||
// Verify the function exists
|
|
||||||
$this->assertTrue(method_exists($user, "fetchPostObjects"));
|
|
||||||
|
|
||||||
/** @var TableGateways\PostsTableGateway $tableGateway */
|
|
||||||
$tableGateway = $this->getDIContainer()->get(TableGateways\PostsTableGateway::class);
|
|
||||||
|
|
||||||
$user->save();
|
|
||||||
|
|
||||||
$this->assertNotNull($user->getId());
|
|
||||||
|
|
||||||
/** @var Models\PostsModel $newPostsModel */
|
|
||||||
$newPostsModel = $tableGateway->getNewMockModelInstance();
|
|
||||||
$newPostsModel->setAuthorId($user->getId());
|
|
||||||
|
|
||||||
// Alas, some non-generic business logic has snuck in here.
|
|
||||||
// If this model has a field called UUID, make it an actual UUID
|
|
||||||
if(method_exists($newPostsModel, 'setUuid')) {
|
|
||||||
$newPostsModel->setUuid(UUID::v4());
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this model has a 'deleted' column, set it to no.
|
|
||||||
if(method_exists($newPostsModel, 'setDeleted')) {
|
|
||||||
$newPostsModel->setDeleted(Models\PostsModel::DELETED_NO);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save our new model. Make offerings to the gods of phpunit & transaction rollback to clean it up afterwards.
|
|
||||||
$newPostsModel->save();
|
|
||||||
$this->assertNotNull($newPostsModel->getAuthorId());
|
|
||||||
|
|
||||||
// Call the singular function on it
|
|
||||||
$postsModel = $user->fetchPostObject();
|
|
||||||
|
|
||||||
$this->assertInstanceOf(Models\PostsModel::class, $postsModel);
|
|
||||||
|
|
||||||
// Call the plural function on it
|
|
||||||
$postModels = $user->fetchPostObjects();
|
|
||||||
|
|
||||||
$this->assertGreaterThanOrEqual(1, count($postModels), "fetchPostObjects() failed to return atleast 1 Models\PostsModel.");
|
|
||||||
$this->assertContainsOnlyInstancesOf(Models\PostsModel::class, $postModels);
|
|
||||||
|
|
||||||
return [$user, $postModels];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends test_RemoteObjects_FetchPostObjects
|
|
||||||
*/
|
|
||||||
public function test_RemoteObjects_CountPostObjects($list)
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var $user Models\UsersModel
|
|
||||||
* @var $postModels Models\PostsModel[]
|
|
||||||
*/
|
|
||||||
list($user, $postModels) = $list;
|
|
||||||
|
|
||||||
// Verify the function exists
|
|
||||||
$this->assertTrue(method_exists($user, "countPostObjects"));
|
|
||||||
|
|
||||||
// Call the function on it
|
|
||||||
$count = $user->countPostObjects();
|
|
||||||
|
|
||||||
$this->assertCount($count, $postModels);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testNewMockModelInstance
|
|
||||||
*/
|
|
||||||
public function test_RemoteObjects_FetchCommentObjects(UsersModel $user)
|
|
||||||
{
|
|
||||||
// Verify the function exists
|
|
||||||
$this->assertTrue(method_exists($user, "fetchCommentObjects"));
|
|
||||||
|
|
||||||
/** @var TableGateways\CommentsTableGateway $tableGateway */
|
|
||||||
$tableGateway = $this->getDIContainer()->get(TableGateways\CommentsTableGateway::class);
|
|
||||||
|
|
||||||
$user->save();
|
|
||||||
|
|
||||||
$this->assertNotNull($user->getId());
|
|
||||||
|
|
||||||
/** @var Models\CommentsModel $newCommentsModel */
|
|
||||||
$newCommentsModel = $tableGateway->getNewMockModelInstance();
|
|
||||||
$newCommentsModel->setAuthorId($user->getId());
|
|
||||||
|
|
||||||
// Alas, some non-generic business logic has snuck in here.
|
|
||||||
// If this model has a field called UUID, make it an actual UUID
|
|
||||||
if(method_exists($newCommentsModel, 'setUuid')) {
|
|
||||||
$newCommentsModel->setUuid(UUID::v4());
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this model has a 'deleted' column, set it to no.
|
|
||||||
if(method_exists($newCommentsModel, 'setDeleted')) {
|
|
||||||
$newCommentsModel->setDeleted(Models\CommentsModel::DELETED_NO);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save our new model. Make offerings to the gods of phpunit & transaction rollback to clean it up afterwards.
|
|
||||||
$newCommentsModel->save();
|
|
||||||
$this->assertNotNull($newCommentsModel->getAuthorId());
|
|
||||||
|
|
||||||
// Call the singular function on it
|
|
||||||
$commentsModel = $user->fetchCommentObject();
|
|
||||||
|
|
||||||
$this->assertInstanceOf(Models\CommentsModel::class, $commentsModel);
|
|
||||||
|
|
||||||
// Call the plural function on it
|
|
||||||
$commentModels = $user->fetchCommentObjects();
|
|
||||||
|
|
||||||
$this->assertGreaterThanOrEqual(1, count($commentModels), "fetchCommentObjects() failed to return atleast 1 Models\CommentsModel.");
|
|
||||||
$this->assertContainsOnlyInstancesOf(Models\CommentsModel::class, $commentModels);
|
|
||||||
|
|
||||||
return [$user, $commentModels];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends test_RemoteObjects_FetchCommentObjects
|
|
||||||
*/
|
|
||||||
public function test_RemoteObjects_CountCommentObjects($list)
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var $user Models\UsersModel
|
|
||||||
* @var $commentModels Models\CommentsModel[]
|
|
||||||
*/
|
|
||||||
list($user, $commentModels) = $list;
|
|
||||||
|
|
||||||
// Verify the function exists
|
|
||||||
$this->assertTrue(method_exists($user, "countCommentObjects"));
|
|
||||||
|
|
||||||
// Call the function on it
|
|
||||||
$count = $user->countCommentObjects();
|
|
||||||
|
|
||||||
$this->assertCount($count, $commentModels);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetPropertyMeta()
|
|
||||||
{
|
|
||||||
$propertyMeta = $this->testInstance->getPropertyMeta();
|
|
||||||
$this->assertTrue(is_array($propertyMeta));
|
|
||||||
$this->assertGreaterThan(0, count($propertyMeta));
|
|
||||||
$this->assertArrayHasKey('id', $propertyMeta);
|
|
||||||
$this->assertArrayHasKey('displayName', $propertyMeta);
|
|
||||||
$this->assertArrayHasKey('userName', $propertyMeta);
|
|
||||||
$this->assertArrayHasKey('email', $propertyMeta);
|
|
||||||
$this->assertArrayHasKey('password', $propertyMeta);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,271 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Test\Services\Generated;
|
|
||||||
|
|
||||||
use \⌬\Config\⌬\⌬ as App;
|
|
||||||
use \Example\BlogApp\TableGateways\CommentsTableGateway;
|
|
||||||
use \Example\BlogApp\Services\CommentsService;
|
|
||||||
use \Example\BlogApp\Models\CommentsModel;
|
|
||||||
use \Laminas\Db\Sql\Select;
|
|
||||||
use ⌬\Tests\BaseTestCase;
|
|
||||||
|
|
||||||
class CommentsTest extends BaseTestCase
|
|
||||||
{
|
|
||||||
/** @var commentsService */
|
|
||||||
protected $commentsService;
|
|
||||||
|
|
||||||
public static function setUpBeforeClass()
|
|
||||||
{
|
|
||||||
$commentsTableGateway = App::Container()->get(CommentsTableGateway::class);
|
|
||||||
parent::setUpBeforeClass();
|
|
||||||
|
|
||||||
for($i = 0; $i <= 5; $i++){
|
|
||||||
$commentsTableGateway
|
|
||||||
->getNewMockModelInstance()
|
|
||||||
->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$this->commentsService = App::Container()->get(CommentsService::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetNewModelInstance()
|
|
||||||
{
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
CommentsModel::class,
|
|
||||||
$this->commentsService->getNewModelInstance()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @large
|
|
||||||
*/
|
|
||||||
public function testGetAll()
|
|
||||||
{
|
|
||||||
$commentsService = App::Container()->get(CommentsService::class);
|
|
||||||
$all = $commentsService->getAll();
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
CommentsModel::class,
|
|
||||||
reset($all)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetRandom()
|
|
||||||
{
|
|
||||||
$commentsService = App::Container()->get(CommentsService::class);
|
|
||||||
|
|
||||||
$random = $commentsService->getRandom();
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
CommentsModel::class,
|
|
||||||
$random
|
|
||||||
);
|
|
||||||
|
|
||||||
return $random;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetById(CommentsModel $random)
|
|
||||||
{
|
|
||||||
$commentsService = App::Container()->get(CommentsService::class);
|
|
||||||
$found = $commentsService->getById($random->getId());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
CommentsModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
$this->assertEquals($random, $found);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testCreateFromArray(CommentsModel $random)
|
|
||||||
{
|
|
||||||
$commentsService = App::Container()->get(CommentsService::class);
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
CommentsModel::class,
|
|
||||||
$commentsService->createFromArray($random->__ToArray())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetMockObject()
|
|
||||||
{
|
|
||||||
$commentsService = App::Container()->get(CommentsService::class);
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
CommentsModel::class,
|
|
||||||
$commentsService->getMockObject()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetByField(CommentsModel $random)
|
|
||||||
{
|
|
||||||
$commentsService = App::Container()->get(CommentsService::class);
|
|
||||||
$found = $commentsService->getByField('id', $random->getid());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
CommentsModel::class,
|
|
||||||
$found,
|
|
||||||
"Calling CommentsService->getByField('id') failed to find a CommentsModel"
|
|
||||||
);
|
|
||||||
$found = $commentsService->getByField('comment', $random->getcomment());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
CommentsModel::class,
|
|
||||||
$found,
|
|
||||||
"Calling CommentsService->getByField('comment') failed to find a CommentsModel"
|
|
||||||
);
|
|
||||||
$found = $commentsService->getByField('authorId', $random->getauthorId());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
CommentsModel::class,
|
|
||||||
$found,
|
|
||||||
"Calling CommentsService->getByField('authorId') failed to find a CommentsModel"
|
|
||||||
);
|
|
||||||
$found = $commentsService->getByField('publishedDate', $random->getpublishedDate());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
CommentsModel::class,
|
|
||||||
$found,
|
|
||||||
"Calling CommentsService->getByField('publishedDate') failed to find a CommentsModel"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testCountByField(CommentsModel $random)
|
|
||||||
{
|
|
||||||
$commentsService = App::Container()->get(CommentsService::class);
|
|
||||||
$found = $commentsService->countByField('id', $random->getid());
|
|
||||||
$this->assertGreaterThanOrEqual(
|
|
||||||
1,
|
|
||||||
$found,
|
|
||||||
"Calling CommentsService->countByField('id') failed to count a CommentsModel"
|
|
||||||
);
|
|
||||||
$found = $commentsService->countByField('comment', $random->getcomment());
|
|
||||||
$this->assertGreaterThanOrEqual(
|
|
||||||
1,
|
|
||||||
$found,
|
|
||||||
"Calling CommentsService->countByField('comment') failed to count a CommentsModel"
|
|
||||||
);
|
|
||||||
$found = $commentsService->countByField('authorId', $random->getauthorId());
|
|
||||||
$this->assertGreaterThanOrEqual(
|
|
||||||
1,
|
|
||||||
$found,
|
|
||||||
"Calling CommentsService->countByField('authorId') failed to count a CommentsModel"
|
|
||||||
);
|
|
||||||
$found = $commentsService->countByField('publishedDate', $random->getpublishedDate());
|
|
||||||
$this->assertGreaterThanOrEqual(
|
|
||||||
1,
|
|
||||||
$found,
|
|
||||||
"Calling CommentsService->countByField('publishedDate') failed to count a CommentsModel"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetManyByField(CommentsModel $random)
|
|
||||||
{
|
|
||||||
$commentsService = App::Container()->get(CommentsService::class);
|
|
||||||
$found = $commentsService->getManyByField('id', $random->getid());
|
|
||||||
$this->assertContainsOnlyInstancesOf(
|
|
||||||
CommentsModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
$found = $commentsService->getManyByField('comment', $random->getcomment());
|
|
||||||
$this->assertContainsOnlyInstancesOf(
|
|
||||||
CommentsModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
$found = $commentsService->getManyByField('authorId', $random->getauthorId());
|
|
||||||
$this->assertContainsOnlyInstancesOf(
|
|
||||||
CommentsModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
$found = $commentsService->getManyByField('publishedDate', $random->getpublishedDate());
|
|
||||||
$this->assertContainsOnlyInstancesOf(
|
|
||||||
CommentsModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetManyMatching(CommentsModel $random)
|
|
||||||
{
|
|
||||||
$all = $this->commentsService->getManyMatching([]);
|
|
||||||
$this->assertGreaterThan(0, count($all));
|
|
||||||
$this->assertContainsOnlyInstancesOf(CommentsModel::class, $all);
|
|
||||||
|
|
||||||
$one = $this->commentsService->getManyMatching([], null, Select::ORDER_ASCENDING, 1);
|
|
||||||
$this->assertEquals(1, count($one));
|
|
||||||
$this->assertContainsOnlyInstancesOf(CommentsModel::class, $one);
|
|
||||||
|
|
||||||
$asc = $this->commentsService->getManyMatching([], 'id', Select::ORDER_ASCENDING);
|
|
||||||
$desc = $this->commentsService->getManyMatching([], 'id', Select::ORDER_DESCENDING);
|
|
||||||
$this->assertContainsOnlyInstancesOf(CommentsModel::class, $asc);
|
|
||||||
$this->assertEquals(count($asc), count($desc));
|
|
||||||
$this->assertEquals($asc, array_reverse($desc));
|
|
||||||
|
|
||||||
$keyValue = $this->commentsService->getManyMatching(['id' => $random->getid()]);
|
|
||||||
$this->assertEquals($random, reset($keyValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetMatching(CommentsModel $random)
|
|
||||||
{
|
|
||||||
$all = $this->commentsService->getMatching([]);
|
|
||||||
$this->assertEquals(commentsModel::class, get_class($all));
|
|
||||||
|
|
||||||
$asc = $this->commentsService->getMatching([], 'id', Select::ORDER_ASCENDING);
|
|
||||||
$desc = $this->commentsService->getMatching([], 'id', Select::ORDER_DESCENDING);
|
|
||||||
$this->assertEquals(commentsModel::class, get_class($asc));
|
|
||||||
$this->assertEquals(commentsModel::class, get_class($desc));
|
|
||||||
$this->assertNotEquals($asc, $desc);
|
|
||||||
|
|
||||||
$keyValue = $this->commentsService->getMatching(['id' => $random->getid()]);
|
|
||||||
$this->assertEquals($random, $keyValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDeleteById()
|
|
||||||
{
|
|
||||||
$commentsService = App::Container()->get(CommentsService::class);
|
|
||||||
$commentsTableGateway = App::Container()->get(CommentsTableGateway::class);
|
|
||||||
|
|
||||||
$deletable = $commentsTableGateway
|
|
||||||
->getNewMockModelInstance()
|
|
||||||
->save();
|
|
||||||
|
|
||||||
$this->assertEquals(1, $commentsService->deleteById($deletable->getId()));
|
|
||||||
|
|
||||||
return $deletable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testDeleteById
|
|
||||||
*/
|
|
||||||
public function testDeleteByIdVerify(CommentsModel $deleted)
|
|
||||||
{
|
|
||||||
$commentsService = App::Container()->get(CommentsService::class);
|
|
||||||
$this->assertEquals(null, $commentsService->getById($deleted->getId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetTermPlural()
|
|
||||||
{
|
|
||||||
$commentsService = App::Container()->get(CommentsService::class);
|
|
||||||
$this->assertNotEmpty($commentsService->getTermPlural());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetTermSingular()
|
|
||||||
{
|
|
||||||
$commentsService = App::Container()->get(CommentsService::class);
|
|
||||||
$this->assertNotEmpty($commentsService->getTermSingular());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,322 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Test\Services\Generated;
|
|
||||||
|
|
||||||
use \⌬\Config\⌬\⌬ as App;
|
|
||||||
use \Example\BlogApp\TableGateways\PostsTableGateway;
|
|
||||||
use \Example\BlogApp\Services\PostsService;
|
|
||||||
use \Example\BlogApp\Models\PostsModel;
|
|
||||||
use \Laminas\Db\Sql\Select;
|
|
||||||
use ⌬\Tests\BaseTestCase;
|
|
||||||
|
|
||||||
class PostsTest extends BaseTestCase
|
|
||||||
{
|
|
||||||
/** @var postsService */
|
|
||||||
protected $postsService;
|
|
||||||
|
|
||||||
public static function setUpBeforeClass()
|
|
||||||
{
|
|
||||||
$postsTableGateway = App::Container()->get(PostsTableGateway::class);
|
|
||||||
parent::setUpBeforeClass();
|
|
||||||
|
|
||||||
for($i = 0; $i <= 5; $i++){
|
|
||||||
$postsTableGateway
|
|
||||||
->getNewMockModelInstance()
|
|
||||||
->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$this->postsService = App::Container()->get(PostsService::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetNewModelInstance()
|
|
||||||
{
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$this->postsService->getNewModelInstance()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @large
|
|
||||||
*/
|
|
||||||
public function testGetAll()
|
|
||||||
{
|
|
||||||
$postsService = App::Container()->get(PostsService::class);
|
|
||||||
$all = $postsService->getAll();
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
PostsModel::class,
|
|
||||||
reset($all)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetRandom()
|
|
||||||
{
|
|
||||||
$postsService = App::Container()->get(PostsService::class);
|
|
||||||
|
|
||||||
$random = $postsService->getRandom();
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$random
|
|
||||||
);
|
|
||||||
|
|
||||||
return $random;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetById(PostsModel $random)
|
|
||||||
{
|
|
||||||
$postsService = App::Container()->get(PostsService::class);
|
|
||||||
$found = $postsService->getById($random->getId());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
$this->assertEquals($random, $found);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testCreateFromArray(PostsModel $random)
|
|
||||||
{
|
|
||||||
$postsService = App::Container()->get(PostsService::class);
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$postsService->createFromArray($random->__ToArray())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetMockObject()
|
|
||||||
{
|
|
||||||
$postsService = App::Container()->get(PostsService::class);
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$postsService->getMockObject()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetByField(PostsModel $random)
|
|
||||||
{
|
|
||||||
$postsService = App::Container()->get(PostsService::class);
|
|
||||||
$found = $postsService->getByField('id', $random->getid());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$found,
|
|
||||||
"Calling PostsService->getByField('id') failed to find a PostsModel"
|
|
||||||
);
|
|
||||||
$found = $postsService->getByField('title', $random->gettitle());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$found,
|
|
||||||
"Calling PostsService->getByField('title') failed to find a PostsModel"
|
|
||||||
);
|
|
||||||
$found = $postsService->getByField('content', $random->getcontent());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$found,
|
|
||||||
"Calling PostsService->getByField('content') failed to find a PostsModel"
|
|
||||||
);
|
|
||||||
$found = $postsService->getByField('authorId', $random->getauthorId());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$found,
|
|
||||||
"Calling PostsService->getByField('authorId') failed to find a PostsModel"
|
|
||||||
);
|
|
||||||
$found = $postsService->getByField('createdDate', $random->getcreatedDate());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$found,
|
|
||||||
"Calling PostsService->getByField('createdDate') failed to find a PostsModel"
|
|
||||||
);
|
|
||||||
$found = $postsService->getByField('publishedDate', $random->getpublishedDate());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$found,
|
|
||||||
"Calling PostsService->getByField('publishedDate') failed to find a PostsModel"
|
|
||||||
);
|
|
||||||
$found = $postsService->getByField('deleted', $random->getdeleted());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$found,
|
|
||||||
"Calling PostsService->getByField('deleted') failed to find a PostsModel"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testCountByField(PostsModel $random)
|
|
||||||
{
|
|
||||||
$postsService = App::Container()->get(PostsService::class);
|
|
||||||
$found = $postsService->countByField('id', $random->getid());
|
|
||||||
$this->assertGreaterThanOrEqual(
|
|
||||||
1,
|
|
||||||
$found,
|
|
||||||
"Calling PostsService->countByField('id') failed to count a PostsModel"
|
|
||||||
);
|
|
||||||
$found = $postsService->countByField('title', $random->gettitle());
|
|
||||||
$this->assertGreaterThanOrEqual(
|
|
||||||
1,
|
|
||||||
$found,
|
|
||||||
"Calling PostsService->countByField('title') failed to count a PostsModel"
|
|
||||||
);
|
|
||||||
$found = $postsService->countByField('content', $random->getcontent());
|
|
||||||
$this->assertGreaterThanOrEqual(
|
|
||||||
1,
|
|
||||||
$found,
|
|
||||||
"Calling PostsService->countByField('content') failed to count a PostsModel"
|
|
||||||
);
|
|
||||||
$found = $postsService->countByField('authorId', $random->getauthorId());
|
|
||||||
$this->assertGreaterThanOrEqual(
|
|
||||||
1,
|
|
||||||
$found,
|
|
||||||
"Calling PostsService->countByField('authorId') failed to count a PostsModel"
|
|
||||||
);
|
|
||||||
$found = $postsService->countByField('createdDate', $random->getcreatedDate());
|
|
||||||
$this->assertGreaterThanOrEqual(
|
|
||||||
1,
|
|
||||||
$found,
|
|
||||||
"Calling PostsService->countByField('createdDate') failed to count a PostsModel"
|
|
||||||
);
|
|
||||||
$found = $postsService->countByField('publishedDate', $random->getpublishedDate());
|
|
||||||
$this->assertGreaterThanOrEqual(
|
|
||||||
1,
|
|
||||||
$found,
|
|
||||||
"Calling PostsService->countByField('publishedDate') failed to count a PostsModel"
|
|
||||||
);
|
|
||||||
$found = $postsService->countByField('deleted', $random->getdeleted());
|
|
||||||
$this->assertGreaterThanOrEqual(
|
|
||||||
1,
|
|
||||||
$found,
|
|
||||||
"Calling PostsService->countByField('deleted') failed to count a PostsModel"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetManyByField(PostsModel $random)
|
|
||||||
{
|
|
||||||
$postsService = App::Container()->get(PostsService::class);
|
|
||||||
$found = $postsService->getManyByField('id', $random->getid());
|
|
||||||
$this->assertContainsOnlyInstancesOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
$found = $postsService->getManyByField('title', $random->gettitle());
|
|
||||||
$this->assertContainsOnlyInstancesOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
$found = $postsService->getManyByField('content', $random->getcontent());
|
|
||||||
$this->assertContainsOnlyInstancesOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
$found = $postsService->getManyByField('authorId', $random->getauthorId());
|
|
||||||
$this->assertContainsOnlyInstancesOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
$found = $postsService->getManyByField('createdDate', $random->getcreatedDate());
|
|
||||||
$this->assertContainsOnlyInstancesOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
$found = $postsService->getManyByField('publishedDate', $random->getpublishedDate());
|
|
||||||
$this->assertContainsOnlyInstancesOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
$found = $postsService->getManyByField('deleted', $random->getdeleted());
|
|
||||||
$this->assertContainsOnlyInstancesOf(
|
|
||||||
PostsModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetManyMatching(PostsModel $random)
|
|
||||||
{
|
|
||||||
$all = $this->postsService->getManyMatching([]);
|
|
||||||
$this->assertGreaterThan(0, count($all));
|
|
||||||
$this->assertContainsOnlyInstancesOf(PostsModel::class, $all);
|
|
||||||
|
|
||||||
$one = $this->postsService->getManyMatching([], null, Select::ORDER_ASCENDING, 1);
|
|
||||||
$this->assertEquals(1, count($one));
|
|
||||||
$this->assertContainsOnlyInstancesOf(PostsModel::class, $one);
|
|
||||||
|
|
||||||
$asc = $this->postsService->getManyMatching([], 'id', Select::ORDER_ASCENDING);
|
|
||||||
$desc = $this->postsService->getManyMatching([], 'id', Select::ORDER_DESCENDING);
|
|
||||||
$this->assertContainsOnlyInstancesOf(PostsModel::class, $asc);
|
|
||||||
$this->assertEquals(count($asc), count($desc));
|
|
||||||
$this->assertEquals($asc, array_reverse($desc));
|
|
||||||
|
|
||||||
$keyValue = $this->postsService->getManyMatching(['id' => $random->getid()]);
|
|
||||||
$this->assertEquals($random, reset($keyValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetMatching(PostsModel $random)
|
|
||||||
{
|
|
||||||
$all = $this->postsService->getMatching([]);
|
|
||||||
$this->assertEquals(postsModel::class, get_class($all));
|
|
||||||
|
|
||||||
$asc = $this->postsService->getMatching([], 'id', Select::ORDER_ASCENDING);
|
|
||||||
$desc = $this->postsService->getMatching([], 'id', Select::ORDER_DESCENDING);
|
|
||||||
$this->assertEquals(postsModel::class, get_class($asc));
|
|
||||||
$this->assertEquals(postsModel::class, get_class($desc));
|
|
||||||
$this->assertNotEquals($asc, $desc);
|
|
||||||
|
|
||||||
$keyValue = $this->postsService->getMatching(['id' => $random->getid()]);
|
|
||||||
$this->assertEquals($random, $keyValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDeleteById()
|
|
||||||
{
|
|
||||||
$postsService = App::Container()->get(PostsService::class);
|
|
||||||
$postsTableGateway = App::Container()->get(PostsTableGateway::class);
|
|
||||||
|
|
||||||
$deletable = $postsTableGateway
|
|
||||||
->getNewMockModelInstance()
|
|
||||||
->save();
|
|
||||||
|
|
||||||
$this->assertEquals(1, $postsService->deleteById($deletable->getId()));
|
|
||||||
|
|
||||||
return $deletable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testDeleteById
|
|
||||||
*/
|
|
||||||
public function testDeleteByIdVerify(PostsModel $deleted)
|
|
||||||
{
|
|
||||||
$postsService = App::Container()->get(PostsService::class);
|
|
||||||
$this->assertEquals(null, $postsService->getById($deleted->getId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetTermPlural()
|
|
||||||
{
|
|
||||||
$postsService = App::Container()->get(PostsService::class);
|
|
||||||
$this->assertNotEmpty($postsService->getTermPlural());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetTermSingular()
|
|
||||||
{
|
|
||||||
$postsService = App::Container()->get(PostsService::class);
|
|
||||||
$this->assertNotEmpty($postsService->getTermSingular());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,288 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Example\BlogApp\Test\Services\Generated;
|
|
||||||
|
|
||||||
use \⌬\Config\⌬\⌬ as App;
|
|
||||||
use \Example\BlogApp\TableGateways\UsersTableGateway;
|
|
||||||
use \Example\BlogApp\Services\UsersService;
|
|
||||||
use \Example\BlogApp\Models\UsersModel;
|
|
||||||
use \Laminas\Db\Sql\Select;
|
|
||||||
use ⌬\Tests\BaseTestCase;
|
|
||||||
|
|
||||||
class UsersTest extends BaseTestCase
|
|
||||||
{
|
|
||||||
/** @var usersService */
|
|
||||||
protected $usersService;
|
|
||||||
|
|
||||||
public static function setUpBeforeClass()
|
|
||||||
{
|
|
||||||
$usersTableGateway = App::Container()->get(UsersTableGateway::class);
|
|
||||||
parent::setUpBeforeClass();
|
|
||||||
|
|
||||||
for($i = 0; $i <= 5; $i++){
|
|
||||||
$usersTableGateway
|
|
||||||
->getNewMockModelInstance()
|
|
||||||
->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$this->usersService = App::Container()->get(UsersService::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetNewModelInstance()
|
|
||||||
{
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
UsersModel::class,
|
|
||||||
$this->usersService->getNewModelInstance()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @large
|
|
||||||
*/
|
|
||||||
public function testGetAll()
|
|
||||||
{
|
|
||||||
$usersService = App::Container()->get(UsersService::class);
|
|
||||||
$all = $usersService->getAll();
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
UsersModel::class,
|
|
||||||
reset($all)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetRandom()
|
|
||||||
{
|
|
||||||
$usersService = App::Container()->get(UsersService::class);
|
|
||||||
|
|
||||||
$random = $usersService->getRandom();
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
UsersModel::class,
|
|
||||||
$random
|
|
||||||
);
|
|
||||||
|
|
||||||
return $random;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetById(UsersModel $random)
|
|
||||||
{
|
|
||||||
$usersService = App::Container()->get(UsersService::class);
|
|
||||||
$found = $usersService->getById($random->getId());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
UsersModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
$this->assertEquals($random, $found);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testCreateFromArray(UsersModel $random)
|
|
||||||
{
|
|
||||||
$usersService = App::Container()->get(UsersService::class);
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
UsersModel::class,
|
|
||||||
$usersService->createFromArray($random->__ToArray())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetMockObject()
|
|
||||||
{
|
|
||||||
$usersService = App::Container()->get(UsersService::class);
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
UsersModel::class,
|
|
||||||
$usersService->getMockObject()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetByField(UsersModel $random)
|
|
||||||
{
|
|
||||||
$usersService = App::Container()->get(UsersService::class);
|
|
||||||
$found = $usersService->getByField('id', $random->getid());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
UsersModel::class,
|
|
||||||
$found,
|
|
||||||
"Calling UsersService->getByField('id') failed to find a UsersModel"
|
|
||||||
);
|
|
||||||
$found = $usersService->getByField('displayName', $random->getdisplayName());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
UsersModel::class,
|
|
||||||
$found,
|
|
||||||
"Calling UsersService->getByField('displayName') failed to find a UsersModel"
|
|
||||||
);
|
|
||||||
$found = $usersService->getByField('userName', $random->getuserName());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
UsersModel::class,
|
|
||||||
$found,
|
|
||||||
"Calling UsersService->getByField('userName') failed to find a UsersModel"
|
|
||||||
);
|
|
||||||
$found = $usersService->getByField('email', $random->getemail());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
UsersModel::class,
|
|
||||||
$found,
|
|
||||||
"Calling UsersService->getByField('email') failed to find a UsersModel"
|
|
||||||
);
|
|
||||||
$found = $usersService->getByField('password', $random->getpassword());
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
UsersModel::class,
|
|
||||||
$found,
|
|
||||||
"Calling UsersService->getByField('password') failed to find a UsersModel"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testCountByField(UsersModel $random)
|
|
||||||
{
|
|
||||||
$usersService = App::Container()->get(UsersService::class);
|
|
||||||
$found = $usersService->countByField('id', $random->getid());
|
|
||||||
$this->assertGreaterThanOrEqual(
|
|
||||||
1,
|
|
||||||
$found,
|
|
||||||
"Calling UsersService->countByField('id') failed to count a UsersModel"
|
|
||||||
);
|
|
||||||
$found = $usersService->countByField('displayName', $random->getdisplayName());
|
|
||||||
$this->assertGreaterThanOrEqual(
|
|
||||||
1,
|
|
||||||
$found,
|
|
||||||
"Calling UsersService->countByField('displayName') failed to count a UsersModel"
|
|
||||||
);
|
|
||||||
$found = $usersService->countByField('userName', $random->getuserName());
|
|
||||||
$this->assertGreaterThanOrEqual(
|
|
||||||
1,
|
|
||||||
$found,
|
|
||||||
"Calling UsersService->countByField('userName') failed to count a UsersModel"
|
|
||||||
);
|
|
||||||
$found = $usersService->countByField('email', $random->getemail());
|
|
||||||
$this->assertGreaterThanOrEqual(
|
|
||||||
1,
|
|
||||||
$found,
|
|
||||||
"Calling UsersService->countByField('email') failed to count a UsersModel"
|
|
||||||
);
|
|
||||||
$found = $usersService->countByField('password', $random->getpassword());
|
|
||||||
$this->assertGreaterThanOrEqual(
|
|
||||||
1,
|
|
||||||
$found,
|
|
||||||
"Calling UsersService->countByField('password') failed to count a UsersModel"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetManyByField(UsersModel $random)
|
|
||||||
{
|
|
||||||
$usersService = App::Container()->get(UsersService::class);
|
|
||||||
$found = $usersService->getManyByField('id', $random->getid());
|
|
||||||
$this->assertContainsOnlyInstancesOf(
|
|
||||||
UsersModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
$found = $usersService->getManyByField('displayName', $random->getdisplayName());
|
|
||||||
$this->assertContainsOnlyInstancesOf(
|
|
||||||
UsersModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
$found = $usersService->getManyByField('userName', $random->getuserName());
|
|
||||||
$this->assertContainsOnlyInstancesOf(
|
|
||||||
UsersModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
$found = $usersService->getManyByField('email', $random->getemail());
|
|
||||||
$this->assertContainsOnlyInstancesOf(
|
|
||||||
UsersModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
$found = $usersService->getManyByField('password', $random->getpassword());
|
|
||||||
$this->assertContainsOnlyInstancesOf(
|
|
||||||
UsersModel::class,
|
|
||||||
$found
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetManyMatching(UsersModel $random)
|
|
||||||
{
|
|
||||||
$all = $this->usersService->getManyMatching([]);
|
|
||||||
$this->assertGreaterThan(0, count($all));
|
|
||||||
$this->assertContainsOnlyInstancesOf(UsersModel::class, $all);
|
|
||||||
|
|
||||||
$one = $this->usersService->getManyMatching([], null, Select::ORDER_ASCENDING, 1);
|
|
||||||
$this->assertEquals(1, count($one));
|
|
||||||
$this->assertContainsOnlyInstancesOf(UsersModel::class, $one);
|
|
||||||
|
|
||||||
$asc = $this->usersService->getManyMatching([], 'id', Select::ORDER_ASCENDING);
|
|
||||||
$desc = $this->usersService->getManyMatching([], 'id', Select::ORDER_DESCENDING);
|
|
||||||
$this->assertContainsOnlyInstancesOf(UsersModel::class, $asc);
|
|
||||||
$this->assertEquals(count($asc), count($desc));
|
|
||||||
$this->assertEquals($asc, array_reverse($desc));
|
|
||||||
|
|
||||||
$keyValue = $this->usersService->getManyMatching(['id' => $random->getid()]);
|
|
||||||
$this->assertEquals($random, reset($keyValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testGetRandom
|
|
||||||
*/
|
|
||||||
public function testGetMatching(UsersModel $random)
|
|
||||||
{
|
|
||||||
$all = $this->usersService->getMatching([]);
|
|
||||||
$this->assertEquals(usersModel::class, get_class($all));
|
|
||||||
|
|
||||||
$asc = $this->usersService->getMatching([], 'id', Select::ORDER_ASCENDING);
|
|
||||||
$desc = $this->usersService->getMatching([], 'id', Select::ORDER_DESCENDING);
|
|
||||||
$this->assertEquals(usersModel::class, get_class($asc));
|
|
||||||
$this->assertEquals(usersModel::class, get_class($desc));
|
|
||||||
$this->assertNotEquals($asc, $desc);
|
|
||||||
|
|
||||||
$keyValue = $this->usersService->getMatching(['id' => $random->getid()]);
|
|
||||||
$this->assertEquals($random, $keyValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDeleteById()
|
|
||||||
{
|
|
||||||
$usersService = App::Container()->get(UsersService::class);
|
|
||||||
$usersTableGateway = App::Container()->get(UsersTableGateway::class);
|
|
||||||
|
|
||||||
$deletable = $usersTableGateway
|
|
||||||
->getNewMockModelInstance()
|
|
||||||
->save();
|
|
||||||
|
|
||||||
$this->assertEquals(1, $usersService->deleteById($deletable->getId()));
|
|
||||||
|
|
||||||
return $deletable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testDeleteById
|
|
||||||
*/
|
|
||||||
public function testDeleteByIdVerify(UsersModel $deleted)
|
|
||||||
{
|
|
||||||
$usersService = App::Container()->get(UsersService::class);
|
|
||||||
$this->assertEquals(null, $usersService->getById($deleted->getId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetTermPlural()
|
|
||||||
{
|
|
||||||
$usersService = App::Container()->get(UsersService::class);
|
|
||||||
$this->assertNotEmpty($usersService->getTermPlural());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetTermSingular()
|
|
||||||
{
|
|
||||||
$usersService = App::Container()->get(UsersService::class);
|
|
||||||
$this->assertNotEmpty($usersService->getTermSingular());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Abstracts;
|
namespace Benzine\ORM\Abstracts;
|
||||||
|
|
||||||
use Camel\CaseTransformer;
|
use Camel\CaseTransformer;
|
||||||
use Camel\Format;
|
use Camel\Format;
|
||||||
use ⌬\Database\Interfaces\ModelInterface;
|
use Benzine\ORM\Interfaces\ModelInterface;
|
||||||
|
|
||||||
abstract class Model implements ModelInterface
|
abstract class Model implements ModelInterface
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Abstracts;
|
namespace Benzine\ORM\Abstracts;
|
||||||
|
|
||||||
use Laminas\Db\ResultSet\ResultSet;
|
use Laminas\Db\ResultSet\ResultSet;
|
||||||
use Laminas\Db\Sql;
|
use Laminas\Db\Sql;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Abstracts;
|
namespace Benzine\ORM\Abstracts;
|
||||||
|
|
||||||
use Laminas\Db\Adapter\AdapterInterface;
|
use Laminas\Db\Adapter\AdapterInterface;
|
||||||
use Laminas\Db\Adapter\Exception\InvalidQueryException;
|
use Laminas\Db\Adapter\Exception\InvalidQueryException;
|
||||||
|
|
@ -10,11 +10,11 @@ use Laminas\Db\Sql\Predicate;
|
||||||
use Laminas\Db\Sql\Predicate\PredicateInterface;
|
use Laminas\Db\Sql\Predicate\PredicateInterface;
|
||||||
use Laminas\Db\Sql\Select;
|
use Laminas\Db\Sql\Select;
|
||||||
use Laminas\Db\Sql\Where;
|
use Laminas\Db\Sql\Where;
|
||||||
use ⌬\Controllers\Filters\FilterCondition;
|
use Benzine\Controllers\Filters\FilterCondition;
|
||||||
use ⌬\Database\Exception\Exception;
|
use Benzine\ORM\Exception\Exception;
|
||||||
use ⌬\Database\Interfaces\ModelInterface;
|
use Benzine\ORM\Interfaces\ModelInterface;
|
||||||
use ⌬\Database\LaminatorSql;
|
use Benzine\ORM\LaminatorSql;
|
||||||
use ⌬\Exceptions\BenzineException;
|
use Benzine\Exceptions\BenzineException;
|
||||||
|
|
||||||
abstract class TableGateway extends \Laminas\Db\TableGateway\TableGateway
|
abstract class TableGateway extends \Laminas\Db\TableGateway\TableGateway
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database;
|
namespace Benzine\ORM;
|
||||||
|
|
||||||
use Laminas\Db\Adapter\Platform;
|
use Laminas\Db\Adapter\Platform;
|
||||||
use Laminas\Db\Adapter\Profiler;
|
use Laminas\Db\Adapter\Profiler;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Components;
|
namespace Benzine\ORM\Components;
|
||||||
|
|
||||||
use ⌬\Database\Exception\DBTypeNotTranslatedException;
|
use Benzine\ORM\Exception\DBTypeNotTranslatedException;
|
||||||
use ⌬\Database\Laminator;
|
use Benzine\ORM\Laminator;
|
||||||
|
|
||||||
class Column extends Entity
|
class Column extends Entity
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Components;
|
namespace Benzine\ORM\Components;
|
||||||
|
|
||||||
use Camel\CaseTransformer;
|
use Camel\CaseTransformer;
|
||||||
use Camel\Format;
|
use Camel\Format;
|
||||||
use ⌬\Database\Laminator;
|
use Benzine\ORM\Laminator;
|
||||||
|
|
||||||
class Entity
|
class Entity
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Components;
|
namespace Benzine\ORM\Components;
|
||||||
|
|
||||||
use Gone\Inflection\Inflect;
|
use Gone\Inflection\Inflect;
|
||||||
use Laminas\Db\Adapter\Adapter as DbAdaptor;
|
use Laminas\Db\Adapter\Adapter as DbAdaptor;
|
||||||
use Laminas\Db\Metadata\Object\ColumnObject;
|
use Laminas\Db\Metadata\Object\ColumnObject;
|
||||||
use Laminas\Db\Metadata\Object\ConstraintObject;
|
use Laminas\Db\Metadata\Object\ConstraintObject;
|
||||||
use ⌬\Database\Laminator;
|
use Benzine\ORM\Laminator;
|
||||||
use ⌬\Exceptions\BenzineException;
|
use Benzine\Exceptions\BenzineException;
|
||||||
|
|
||||||
class Model extends Entity
|
class Model extends Entity
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Components;
|
namespace Benzine\ORM\Components;
|
||||||
|
|
||||||
use Gone\Inflection\Inflect;
|
use Gone\Inflection\Inflect;
|
||||||
use ⌬\Database\Laminator;
|
use Benzine\ORM\Laminator;
|
||||||
|
|
||||||
class RelatedModel extends Entity
|
class RelatedModel extends Entity
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database;
|
namespace Benzine\ORM;
|
||||||
|
|
||||||
use ⌬\Configuration\DatabaseConfig;
|
use Benzine\Configuration\DatabaseConfig;
|
||||||
use ⌬\Database\Exception\Exception as DbException;
|
use Benzine\ORM\Exception\Exception as DbException;
|
||||||
|
|
||||||
class Db
|
class Db
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Entities;
|
namespace Benzine\ORM\Entities;
|
||||||
|
|
||||||
class Column extends Entity
|
class Column extends Entity
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Entities;
|
namespace Benzine\ORM\Entities;
|
||||||
|
|
||||||
use ⌬\Migrator\Traits\Support;
|
use Benzine\Migrator\Traits\Support;
|
||||||
|
|
||||||
abstract class Entity
|
abstract class Entity
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Entities;
|
namespace Benzine\ORM\Entities;
|
||||||
|
|
||||||
class Table extends Entity
|
class Table extends Entity
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Exception;
|
namespace Benzine\ORM\Exception;
|
||||||
|
|
||||||
class DBTypeNotTranslatedException extends Exception
|
class DBTypeNotTranslatedException extends Exception
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Exception;
|
namespace Benzine\ORM\Exception;
|
||||||
|
|
||||||
class Exception extends \Exception
|
class Exception extends \Exception
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Exception;
|
namespace Benzine\ORM\Exception;
|
||||||
|
|
||||||
class SchemaToAdaptorException extends Exception
|
class SchemaToAdaptorException extends Exception
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
require_once (__DIR__ . "/find-autoloader.php");
|
|
||||||
ini_set("memory_limit", "256M");
|
|
||||||
|
|
||||||
$scope = APP_CORE_NAME;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$databaseConfigs = $scope::Container()->get(\Gone\AppCore\DbConfig::class);
|
|
||||||
}catch(\Gone\AppCore\Exceptions\DbConfigException $dbConfigException){
|
|
||||||
$databaseConfigs = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$laminator = new \⌬\Database\Laminator(
|
|
||||||
$rootOfApp,
|
|
||||||
$databaseConfigs
|
|
||||||
);
|
|
||||||
$laminator->cleanCodePHPCSFixer();
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
use CliArgs\CliArgs;
|
|
||||||
use ⌬\Configuration\Configuration;
|
|
||||||
use ⌬\Database\Laminator;
|
|
||||||
|
|
||||||
require_once (__DIR__ . "/find-autoloader.php");
|
|
||||||
|
|
||||||
ini_set("memory_limit", "256M");
|
|
||||||
|
|
||||||
$cliArgs = new CliArgs([
|
|
||||||
'workdir' => ['alias' => 'w', 'help' => "The path you want to look for a .benzine.yml file"],
|
|
||||||
'models' => ['help' => 'Limit laminator to a comma-seperated list of specific models']
|
|
||||||
]);
|
|
||||||
|
|
||||||
$workDir = realpath(getcwd() . "/" . $cliArgs->getArg('workdir'));
|
|
||||||
|
|
||||||
$benzineYamlFile = $workDir . "/.benzine.yml";
|
|
||||||
if(!file_exists($benzineYamlFile)){
|
|
||||||
die("Cannot find .benzine.yml in {$workDir}!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
$benzineConfig = Configuration::InitFromFile($benzineYamlFile);
|
|
||||||
|
|
||||||
$laminator = new Laminator(
|
|
||||||
$workDir,
|
|
||||||
$benzineConfig
|
|
||||||
);
|
|
||||||
$laminator->makeLaminator(false, $cliArgs);
|
|
||||||
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
require_once (__DIR__ . "/find-autoloader.php");
|
|
||||||
ini_set("memory_limit", "256M");
|
|
||||||
|
|
||||||
$scope = APP_CORE_NAME;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$databaseConfigs = $scope::Container()->get(\Gone\AppCore\DbConfig::class);
|
|
||||||
}catch(\Gone\AppCore\Exceptions\DbConfigException $dbConfigException){
|
|
||||||
$databaseConfigs = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$Laminator = new \⌬\Database\Laminator(
|
|
||||||
$rootOfApp,
|
|
||||||
$databaseConfigs
|
|
||||||
);
|
|
||||||
$Laminator->cleanCodePHPCSFixer();
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
require_once (__DIR__ . "/find-autoloader.php");
|
|
||||||
|
|
||||||
ini_set("memory_limit", "256M");
|
|
||||||
|
|
||||||
$sdkOutputPath = isset($argv[1]) ? $argv[1] : APP_ROOT . "/vendor/gone.io/lib" . strtolower(APP_NAME) . "/";
|
|
||||||
$appName = isset($argv[2]) ? $argv[2] : null;
|
|
||||||
$remoteApiUri = isset($argv[3]) ? $argv[3] : null;
|
|
||||||
$namespace = isset($argv[4]) ? $argv[4] : "Gone";
|
|
||||||
|
|
||||||
define("APP_NAMESPACE", $namespace);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$databaseConfigs = $scope::Container()->get(\⌬\Database\DbConfig::class);
|
|
||||||
}catch(\Gone\AppCore\Exceptions\DbConfigException $dbConfigException){
|
|
||||||
$databaseConfigs = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$laminator = new \⌬\Database\Laminator(
|
|
||||||
$rootOfApp,
|
|
||||||
$databaseConfigs
|
|
||||||
);
|
|
||||||
|
|
||||||
$laminator->runSdkifier($sdkOutputPath, $remoteApiUri);
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace {{ namespace }}\Test\Api\Generated;
|
||||||
|
|
||||||
use {{ namespace }}\Models\{{ class_name }}Model;
|
use {{ namespace }}\Models\{{ class_name }}Model;
|
||||||
use {{ namespace }}\Services\{{ class_name }}Service;
|
use {{ namespace }}\Services\{{ class_name }}Service;
|
||||||
use ⌬\Tests\RoutesTestCase;
|
use Benzine\Tests\RoutesTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \{{ namespace }}\Controllers\{{ class_name }}Controller
|
* @covers \{{ namespace }}\Controllers\{{ class_name }}Controller
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
namespace {{ namespace }}\Controllers\Base;
|
namespace {{ namespace }}\Controllers\Base;
|
||||||
|
|
||||||
use {{ namespace }}\Services;
|
use {{ namespace }}\Services;
|
||||||
use ⌬\Controllers\Abstracts\CrudController as AbstractCrudController;
|
use Benzine\Controllers\Abstracts\CrudController as AbstractCrudController;
|
||||||
|
|
||||||
{% include '_overwrite_warning.twig' %}
|
{% include '_overwrite_warning.twig' %}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@ use {{ namespace }}\TableGateways;
|
||||||
use {{ namespace }}\Services;
|
use {{ namespace }}\Services;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use ⌬\Database\Abstracts\Model as AbstractModel;
|
use Benzine\ORM\Abstracts\Model as AbstractModel;
|
||||||
use ⌬\Database\Interfaces\ModelInterface as ModelInterface;
|
use Benzine\ORM\Interfaces\ModelInterface as ModelInterface;
|
||||||
use ⌬\⌬ as App;
|
use Benzine\⌬ as App;
|
||||||
|
|
||||||
{% include '_overwrite_warning.twig' %}
|
{% include '_overwrite_warning.twig' %}
|
||||||
{% set existingMethods = [] %}
|
{% set existingMethods = [] %}
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ use {{ namespace }}\Models;
|
||||||
use {{ namespace }}\TableGateways;
|
use {{ namespace }}\TableGateways;
|
||||||
use Faker\Generator;
|
use Faker\Generator;
|
||||||
use Laminas\Db\ResultSet\ResultSet;
|
use Laminas\Db\ResultSet\ResultSet;
|
||||||
use ⌬\Database\Abstracts\Model;
|
use Benzine\ORM\Abstracts\Model;
|
||||||
use ⌬\Database\Abstracts\TableGateway as AbstractTableGateway;
|
use Benzine\ORM\Abstracts\TableGateway as AbstractTableGateway;
|
||||||
use ⌬\Database\Adapter;
|
use Benzine\ORM\Adapter;
|
||||||
use ⌬\Database\Db;
|
use Benzine\ORM\Db;
|
||||||
use ⌬\Database\Exception\Exception as DbException;
|
use Benzine\ORM\Exception\Exception as DbException;
|
||||||
use ⌬\Database\Interfaces\TableGatewayInterface as TableGatewayInterface;
|
use Benzine\ORM\Interfaces\TableGatewayInterface as TableGatewayInterface;
|
||||||
|
|
||||||
{% include '_overwrite_warning.twig' %}
|
{% include '_overwrite_warning.twig' %}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use {{ namespace }}\Models;
|
||||||
use {{ namespace }}\Models\{{ class_name }}Model;
|
use {{ namespace }}\Models\{{ class_name }}Model;
|
||||||
use {{ namespace }}\TableGateways;
|
use {{ namespace }}\TableGateways;
|
||||||
use {{ namespace }}\TableGateways\{{ class_name }}TableGateway;
|
use {{ namespace }}\TableGateways\{{ class_name }}TableGateway;
|
||||||
use ⌬\Tests\BaseTestCase;
|
use Benzine\Tests\BaseTestCase;
|
||||||
|
|
||||||
{% set existingMethods = [] %}
|
{% set existingMethods = [] %}
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use {{ namespace }}\Models\{{ class_name }}Model;
|
use {{ namespace }}\Models\{{ class_name }}Model;
|
||||||
use {{ namespace }}\TableGateways\{{ class_name }}TableGateway;
|
use {{ namespace }}\TableGateways\{{ class_name }}TableGateway;
|
||||||
use ⌬\Router\Route;
|
use Benzine\Router\Route;
|
||||||
|
|
||||||
if (!defined('DEFAULT_ROUTE_ACCESS_MODE')) {
|
if (!defined('DEFAULT_ROUTE_ACCESS_MODE')) {
|
||||||
define('DEFAULT_ROUTE_ACCESS_MODE', 'public');
|
define('DEFAULT_ROUTE_ACCESS_MODE', 'public');
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ use Laminas\Db\Sql\Expression;
|
||||||
use Laminas\Db\Sql\Select;
|
use Laminas\Db\Sql\Select;
|
||||||
use Laminas\Db\Sql\Predicate;
|
use Laminas\Db\Sql\Predicate;
|
||||||
use Laminas\Db\Sql\Where;
|
use Laminas\Db\Sql\Where;
|
||||||
use ⌬\Database\Abstracts\Service as AbstractService;
|
use Benzine\ORM\Abstracts\Service as AbstractService;
|
||||||
use ⌬\Database\Interfaces\ServiceInterface as ServiceInterface;
|
use Benzine\ORM\Interfaces\ServiceInterface as ServiceInterface;
|
||||||
|
|
||||||
{% include '_overwrite_warning.twig' %}
|
{% include '_overwrite_warning.twig' %}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use {{ namespace }}\Services;
|
||||||
use {{ namespace }}\Models\{{ class_name }}Model;
|
use {{ namespace }}\Models\{{ class_name }}Model;
|
||||||
use Laminas\Db\Sql\Select;
|
use Laminas\Db\Sql\Select;
|
||||||
use Laminas\Db\Sql\Where;
|
use Laminas\Db\Sql\Where;
|
||||||
use ⌬\Tests\BaseTestCase;
|
use Benzine\Tests\BaseTestCase;
|
||||||
use \⌬\⌬ as App;
|
use \⌬\⌬ as App;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
use CliArgs\CliArgs;
|
|
||||||
use ⌬\Configuration\Configuration;
|
|
||||||
use ⌬\Database\Laminator;
|
|
||||||
|
|
||||||
require_once (__DIR__ . "/find-autoloader.php");
|
|
||||||
|
|
||||||
(new ⌬\⌬())::waitForMySQLToBeReady();
|
|
||||||
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Interfaces;
|
namespace Benzine\ORM\Interfaces;
|
||||||
|
|
||||||
interface ModelInterface
|
interface ModelInterface
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Interfaces;
|
namespace Benzine\ORM\Interfaces;
|
||||||
|
|
||||||
interface QueryStatisticInterface
|
interface QueryStatisticInterface
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Interfaces;
|
namespace Benzine\ORM\Interfaces;
|
||||||
|
|
||||||
use Laminas\Db\Sql\Expression;
|
use Laminas\Db\Sql\Expression;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Interfaces;
|
namespace Benzine\ORM\Interfaces;
|
||||||
|
|
||||||
interface TableGatewayInterface extends \Zend\Db\TableGateway\TableGatewayInterface
|
interface TableGatewayInterface extends \Zend\Db\TableGateway\TableGatewayInterface
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database;
|
namespace Benzine\ORM;
|
||||||
|
|
||||||
|
use Benzine\Services\ConfigurationService;
|
||||||
use Camel\CaseTransformer;
|
use Camel\CaseTransformer;
|
||||||
use Camel\Format;
|
use Camel\Format;
|
||||||
use CliArgs\CliArgs;
|
use CliArgs\CliArgs;
|
||||||
|
|
@ -23,12 +24,12 @@ use Slim\Http\Uri;
|
||||||
use Twig\Error\LoaderError;
|
use Twig\Error\LoaderError;
|
||||||
use Twig\Error\RuntimeError;
|
use Twig\Error\RuntimeError;
|
||||||
use Twig\Error\SyntaxError;
|
use Twig\Error\SyntaxError;
|
||||||
use ⌬\Configuration\Configuration;
|
use Benzine\Configuration\Configuration;
|
||||||
use ⌬\Configuration\DatabaseConfig as DbConfig;
|
use Benzine\Configuration\DatabaseConfig as DbConfig;
|
||||||
use ⌬\Configuration\Exceptions\Exception;
|
use Benzine\Configuration\Exceptions\Exception;
|
||||||
use ⌬\Database\Components\Model;
|
use Benzine\ORM\Components\Model;
|
||||||
use ⌬\Database\Exception\SchemaToAdaptorException;
|
use Benzine\ORM\Exception\SchemaToAdaptorException;
|
||||||
use ⌬\Database\Twig\Extensions\ArrayUniqueTwigExtension;
|
use Benzine\ORM\Twig\Extensions\ArrayUniqueTwigExtension;
|
||||||
|
|
||||||
class Laminator
|
class Laminator
|
||||||
{
|
{
|
||||||
|
|
@ -41,7 +42,7 @@ class Laminator
|
||||||
public CaseTransformer $transCamel2Snake;
|
public CaseTransformer $transCamel2Snake;
|
||||||
/** @var Path to code source. */
|
/** @var Path to code source. */
|
||||||
private string $workPath;
|
private string $workPath;
|
||||||
private static Configuration $benzineConfig;
|
private static ConfigurationService $benzineConfig;
|
||||||
private array $config = [
|
private array $config = [
|
||||||
'templates' => [],
|
'templates' => [],
|
||||||
'formatting' => [],
|
'formatting' => [],
|
||||||
|
|
@ -111,7 +112,7 @@ class Laminator
|
||||||
private array $defaultHeaders = [];
|
private array $defaultHeaders = [];
|
||||||
private CliArgs $cliArgs;
|
private CliArgs $cliArgs;
|
||||||
|
|
||||||
public function __construct(string $workPath, Configuration $benzineConfig)
|
public function __construct(string $workPath, ConfigurationService $benzineConfig)
|
||||||
{
|
{
|
||||||
$this->workPath = $workPath;
|
$this->workPath = $workPath;
|
||||||
self::$benzineConfig = $benzineConfig;
|
self::$benzineConfig = $benzineConfig;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database;
|
namespace Benzine\ORM;
|
||||||
|
|
||||||
use Laminas\Db\Adapter\AdapterInterface;
|
use Laminas\Db\Adapter\AdapterInterface;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Profiler;
|
namespace Benzine\ORM\Profiler;
|
||||||
|
|
||||||
use Laminas\Db\Adapter\ParameterContainer;
|
use Laminas\Db\Adapter\ParameterContainer;
|
||||||
use Laminas\Db\Adapter\Profiler\ProfilerInterface;
|
use Laminas\Db\Adapter\Profiler\ProfilerInterface;
|
||||||
use ⌬\Database\Interfaces\QueryStatisticInterface;
|
use Benzine\ORM\Interfaces\QueryStatisticInterface;
|
||||||
use ⌬\Log\Logger;
|
use Benzine\Log\Logger;
|
||||||
use ⌬\UUID\UUID;
|
use Benzine\UUID\UUID;
|
||||||
|
|
||||||
class Profiler implements ProfilerInterface
|
class Profiler implements ProfilerInterface
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Profiler;
|
namespace Benzine\ORM\Profiler;
|
||||||
|
|
||||||
use ⌬\Database\Interfaces\QueryStatisticInterface;
|
use Benzine\ORM\Interfaces\QueryStatisticInterface;
|
||||||
|
|
||||||
class QueryStatistic implements QueryStatisticInterface
|
class QueryStatistic implements QueryStatisticInterface
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Twig\Extensions;
|
namespace Benzine\ORM\Twig\Extensions;
|
||||||
|
|
||||||
class ArrayUniqueTwigExtension extends \Twig_Extension
|
class ArrayUniqueTwigExtension extends \Twig_Extension
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Twig\Extensions;
|
namespace Benzine\ORM\Twig\Extensions;
|
||||||
|
|
||||||
class ArrayValuesTwigExtension extends \Twig_Extension
|
class ArrayValuesTwigExtension extends \Twig_Extension
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ⌬\Database\Twig\Extensions;
|
namespace Benzine\ORM\Twig\Extensions;
|
||||||
|
|
||||||
class FilterAlphanumericOnlyTwigExtension extends \Twig_Extension
|
class FilterAlphanumericOnlyTwigExtension extends \Twig_Extension
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue