Skip to content

Commit

Permalink
Merge pull request #85 from phalcon/feature/#79-tests-implementation
Browse files Browse the repository at this point in the history
#79 - Tests implementation
  • Loading branch information
Jeckerson authored Jan 16, 2020
2 parents 856c986 + ddef596 commit 45faa9f
Show file tree
Hide file tree
Showing 34 changed files with 473 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Models/ProductTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function initialize()
{
$this->hasMany(
'id',
'Products',
Products::class,
'product_types_id',
[
'foreignKey' => [
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function initialize()
{
$this->belongsTo(
'product_types_id',
'ProductTypes',
ProductTypes::class,
'id',
[
'reusable' => true,
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* Read the configuration
*/
final class ConfigProvider implements ServiceProviderInterface
class ConfigProvider implements ServiceProviderInterface
{
public function register(DiInterface $di): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/DatabaseProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* Database connection is created based in the parameters defined in the configuration file
*/
final class DatabaseProvider implements ServiceProviderInterface
class DatabaseProvider implements ServiceProviderInterface
{
public function register(DiInterface $di): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/DispatcherProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* We register the events manager
*/
final class DispatcherProvider implements ServiceProviderInterface
class DispatcherProvider implements ServiceProviderInterface
{
public function register(DiInterface $di): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/FlashProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* Register the flash service with custom CSS classes
*/
final class FlashProvider implements ServiceProviderInterface
class FlashProvider implements ServiceProviderInterface
{
public function register(DiInterface $di): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/SessionBagProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Phalcon\Di\ServiceProviderInterface;
use Phalcon\Session\Bag;

final class SessionBagProvider implements ServiceProviderInterface
class SessionBagProvider implements ServiceProviderInterface
{
public function register(DiInterface $di): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/SessionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* Start the session the first time some component request the session service
*/
final class SessionProvider implements ServiceProviderInterface
class SessionProvider implements ServiceProviderInterface
{
public function register(DiInterface $di): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/UrlProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* The URL component is used to generate all kind of urls in the application
*/
final class UrlProvider implements ServiceProviderInterface
class UrlProvider implements ServiceProviderInterface
{
public function register(DiInterface $di): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/ViewProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Phalcon\Di\ServiceProviderInterface;
use Phalcon\Mvc\View;

final class ViewProvider implements ServiceProviderInterface
class ViewProvider implements ServiceProviderInterface
{
public function register(DiInterface $di): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/VoltProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Phalcon\Di\ServiceProviderInterface;
use Phalcon\Mvc\View\Engine\Volt as VoltEngine;

final class VoltProvider implements ServiceProviderInterface
class VoltProvider implements ServiceProviderInterface
{
public function register(DiInterface $di): void
{
Expand Down
43 changes: 43 additions & 0 deletions tests/functional/Forms/ProductTypesFormTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);

namespace Invo\Tests\Functional\Forms;

use Codeception\Test\Unit;
use Invo\Forms\ProductTypesForm;
use Phalcon\Di;
use Phalcon\Filter;

final class ProductTypesFormTest extends Unit
{
public function inputDataProvider(): array
{
$key = 'name';

return [
[[$key => 'string'], true],
[[$key => '<h1>Title</h1>'], true],
[[$key => 1], true],
[[], false],
];
}

/**
* @dataProvider inputDataProvider
*
* @param array $data
* @param bool $expected
*/
public function testValidation(array $data, bool $expected): void
{
$di = new Di();
$di['filter'] = function () {
return new Filter();
};

$form = new ProductTypesForm();
$form->setDI($di);

$this->assertSame($expected, $form->isValid($data));
}
}
30 changes: 30 additions & 0 deletions tests/functional/Models/ContactTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);

namespace Invo\Tests\Functional\Models;

use Codeception\Test\Unit;
use Invo\Models\Contact;
use Phalcon\Db\RawValue;
use Phalcon\Di;
use Phalcon\Mvc\Model\Manager;

final class ContactTest extends Unit
{
public function testBeforeCreate(): void
{
$di = new Di();
$di['modelsManager'] = function () {
return new Manager();
};

$class = new Contact();
$class->setDI($di);
$class->beforeCreate();

/** @var RawValue $raw */
$raw = $class->created_at;

$this->assertSame('now()', $raw->__toString());
}
}
29 changes: 29 additions & 0 deletions tests/unit/Forms/CompaniesFormTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);

namespace Invo\Tests\Unit\Forms;

use Codeception\Test\Unit;
use Invo\Forms\CompaniesForm;
use Phalcon\Forms\Element\Hidden;
use Phalcon\Forms\Element\Text;
use Phalcon\Forms\Form;

final class CompaniesFormTest extends Unit
{
public function testImplementation(): void
{
$class = $this->createMock(CompaniesForm::class);

$this->assertInstanceOf(Form::class, $class);
}

public function testIdElementType(): void
{
$createForm = new CompaniesForm();
$editForm = new CompaniesForm(null, ['edit' => true]);

$this->assertInstanceOf(Text::class, $createForm->getElements()['id']);
$this->assertInstanceOf(Hidden::class, $editForm->getElements()['id']);
}
}
18 changes: 18 additions & 0 deletions tests/unit/Forms/ContactFormTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace Invo\Tests\Unit\Forms;

use Codeception\Test\Unit;
use Invo\Forms\ContactForm;
use Phalcon\Forms\Form;

final class ContactFormTest extends Unit
{
public function testImplementation(): void
{
$class = $this->createMock(ContactForm::class);

$this->assertInstanceOf(Form::class, $class);
}
}
18 changes: 18 additions & 0 deletions tests/unit/Forms/ProductTypesFormTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace Invo\Tests\Unit\Forms;

use Codeception\Test\Unit;
use Invo\Forms\ProductTypesForm;
use Phalcon\Forms\Form;

final class ProductTypesFormTest extends Unit
{
public function testImplementation(): void
{
$class = $this->createMock(ProductTypesForm::class);

$this->assertInstanceOf(Form::class, $class);
}
}
18 changes: 18 additions & 0 deletions tests/unit/Forms/ProductsFormTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace Invo\Tests\Unit\Forms;

use Codeception\Test\Unit;
use Invo\Forms\ProductsForm;
use Phalcon\Forms\Form;

final class ProductsFormTest extends Unit
{
public function testImplementation(): void
{
$class = $this->createMock(ProductsForm::class);

$this->assertInstanceOf(Form::class, $class);
}
}
18 changes: 18 additions & 0 deletions tests/unit/Forms/RegisterFormTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace Invo\Tests\Unit\Forms;

use Codeception\Test\Unit;
use Invo\Forms\RegisterForm;
use Phalcon\Forms\Form;

final class RegisterFormTest extends Unit
{
public function testImplementation(): void
{
$class = $this->createMock(RegisterForm::class);

$this->assertInstanceOf(Form::class, $class);
}
}
18 changes: 18 additions & 0 deletions tests/unit/Models/CompaniesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace Invo\Tests\Unit\Models;

use Codeception\Test\Unit;
use Invo\Models\Companies;
use Phalcon\Mvc\Model;

final class CompaniesTest extends Unit
{
public function testImplementation(): void
{
$class = $this->createMock(Companies::class);

$this->assertInstanceOf(Model::class, $class);
}
}
18 changes: 18 additions & 0 deletions tests/unit/Models/ContactTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace Invo\Tests\Unit\Models;

use Codeception\Test\Unit;
use Invo\Models\Contact;
use Phalcon\Mvc\Model;

final class ContactTest extends Unit
{
public function testImplementation(): void
{
$class = $this->createMock(Contact::class);

$this->assertInstanceOf(Model::class, $class);
}
}
18 changes: 18 additions & 0 deletions tests/unit/Models/ProductTypesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace Invo\Tests\Unit\Models;

use Codeception\Test\Unit;
use Invo\Models\ProductTypes;
use Phalcon\Mvc\Model;

final class ProductTypesTest extends Unit
{
public function testImplementation(): void
{
$class = $this->createMock(ProductTypes::class);

$this->assertInstanceOf(Model::class, $class);
}
}
18 changes: 18 additions & 0 deletions tests/unit/Models/ProductsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace Invo\Tests\Unit\Models;

use Codeception\Test\Unit;
use Invo\Models\Products;
use Phalcon\Mvc\Model;

final class ProductsTest extends Unit
{
public function testImplementation(): void
{
$class = $this->createMock(Products::class);

$this->assertInstanceOf(Model::class, $class);
}
}
18 changes: 18 additions & 0 deletions tests/unit/Models/UsersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace Invo\Tests\Unit\Models;

use Codeception\Test\Unit;
use Invo\Models\Users;
use Phalcon\Mvc\Model;

final class UsersTest extends Unit
{
public function testImplementation(): void
{
$class = $this->createMock(Users::class);

$this->assertInstanceOf(Model::class, $class);
}
}
18 changes: 18 additions & 0 deletions tests/unit/Plugins/NotFoundPluginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace Invo\Tests\Unit\Plugins;

use Codeception\Test\Unit;
use Invo\Plugins\NotFoundPlugin;
use Phalcon\Di\Injectable;

final class NotFoundPluginTest extends Unit
{
public function testImplementation(): void
{
$class = $this->createMock(NotFoundPlugin::class);

$this->assertInstanceOf(Injectable::class, $class);
}
}
Loading

0 comments on commit 45faa9f

Please sign in to comment.