Skip to content

Commit

Permalink
Tests namespaces, Fix #8
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonOkulov committed Jan 27, 2019
1 parent 50285de commit c361ac3
Show file tree
Hide file tree
Showing 82 changed files with 238 additions and 92 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"Phact\\Cache\\": "src/Phact/Cache",
"Phact\\Log\\": "src/Phact/Log",
"Phact\\Translate\\": "src/Phact/Translate",
"Phact\\Di\\": "src/Phact/Di"
"Phact\\Di\\": "src/Phact/Di",
"Phact\\Tests\\": "tests"
},
"files": [
"src/dump.php"
Expand Down
7 changes: 4 additions & 3 deletions src/Phact/Orm/QueryLayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,16 @@ public function isSafeAttribute($attribute)
public function processJoins($queryBuilder)
{
$relations = $this->getQuerySet()->getRelations();

foreach ($relations as $relationName => $relation) {
// A relation and a table on which a join is to be build
$currentRelationName = $this->getQuerySet()->parentRelationName($relationName);
$currentTable = $this->getRelationTable($currentRelationName);
$currentAlias = null;
$currentAlias = $this->getAlias($currentRelationName, $currentTable);

if (isset($relation['joins']) && is_array($relation['joins'])) {


foreach ($relation['joins'] as $join) {
if (is_array($join)) {
if (isset($join['table']) && isset($join['from']) && isset($join['to'])) {
Expand Down Expand Up @@ -522,7 +525,6 @@ public function values($columns = [], $distinct = true, $sql = false)
{
$queryBuilder = $this->getQueryBuilder();
$qs = $this->getQuerySet();

if (!$columns) {
$select = [$this->column($this->getTableName(), '*')];
} else {
Expand All @@ -542,7 +544,6 @@ public function values($columns = [], $distinct = true, $sql = false)
$select[] = $item . ($alias ? ' AS ' . $alias: '');
}
}

if ($qs->getHasManyRelations() && $distinct) {
reset($select);
$first = key($select);
Expand Down
3 changes: 2 additions & 1 deletion tests/Cases/Application/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
* @date 09/04/16 11:26
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Application;

use Phact\Main\Phact;
use Phact\Tests\Templates\TestCase;

class ApplicationTest extends TestCase
{
Expand Down
4 changes: 3 additions & 1 deletion tests/Cases/Application/CliApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
* @date 09/04/16 11:26
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Application;

use Modules\Test\Commands\TestCommand;
use Phact\Main\Phact;
use Phact\Request\HttpRequest;
use Phact\Router\Router;
use Phact\Tests\Mock\CliTestRequest;
use Phact\Tests\Templates\TestCase;

class CliApplicationTest extends TestCase
{
Expand Down
6 changes: 5 additions & 1 deletion tests/Cases/Application/WebApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
* @date 09/04/16 11:26
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Application;

use Phact\Main\Phact;
use Phact\Request\HttpRequest;
use Phact\Router\Router;
use Phact\Tests\Mock\ArgumentsTestController;
use Phact\Tests\Mock\DiTestController;
use Phact\Tests\Mock\HttpTestRequest;
use Phact\Tests\Templates\TestCase;

class WebApplicationTest extends TestCase
{
Expand Down
5 changes: 3 additions & 2 deletions tests/Cases/Controller/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
* @date 09/04/16 11:26
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Controller;

use InvalidArgumentException;
use Modules\Test\Controllers\TestController;
use Phact\Controller\Controller;
use Phact\Main\Phact;
use Phact\Request\HttpRequest;
use Phact\Router\Router;
use Phact\Tests\Templates\AppTest;

/**
* Class ControllerTest
* @package Phact\Tests
* @package Phact\Tests\Cases
*/
class ControllerTest extends AppTest
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Cases/Di/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @date 20/09/2018 12:19
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Di;

use Modules\Test\Components\ArgumentsComponent;
use Modules\Test\Components\CrossComponent1;
Expand All @@ -25,6 +25,7 @@
use Modules\Test\Components\StandaloneComponentInterface;
use Phact\Di\Container;
use Phact\Exceptions\CircularContainerException;
use Phact\Tests\Templates\TestCase;

class ContainerTest extends TestCase
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Cases/Event/EventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
* @date 09/04/16 11:26
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Event;

use Phact\Event\EventManager;
use Phact\Tests\Templates\AppTest;

class EventsTest extends AppTest
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Cases/Form/DefaultModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @date 10/04/16 08:21
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Form;


use Modules\Test\Forms\RequiredForm;
Expand All @@ -19,6 +19,7 @@
use Modules\Test\Models\Company;
use Phact\Form\Form;
use Phact\Form\ModelForm;
use Phact\Tests\Templates\DatabaseTest;

class DefaultModelTest extends DatabaseTest
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Cases/Form/ModelOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
* @date 10/04/16 08:21
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Form;

use Modules\Test\Forms\CompanyDefaultForm;
use Modules\Test\Forms\CompanyFoundedForm;
use Modules\Test\Models\Company;
use Phact\Tests\Templates\DatabaseTest;

class ModelOptionsTest extends DatabaseTest
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Cases/Form/RequiredTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
* @date 10/04/16 08:21
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Form;


use Modules\Test\Forms\RequiredForm;
use Phact\Form\Form;
use Phact\Tests\Templates\AppTest;

class RequiredTest extends AppTest
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Cases/Form/SimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
* @date 10/04/16 08:21
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Form;


use Modules\Test\Forms\SimpleForm;
use Phact\Form\Form;
use Phact\Tests\Templates\AppTest;

class SimpleTest extends AppTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @date 10/04/16 10:14
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Orm\Abs;

use Modules\Test\Models\Author;
use Modules\Test\Models\Book;
Expand All @@ -19,6 +19,7 @@
use Modules\Test\Models\Note;
use Modules\Test\Models\NoteThesis;
use Phact\Orm\Fields\HasManyField;
use Phact\Tests\Templates\DatabaseTest;

abstract class AbstractBasicRelationsTest extends DatabaseTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
* @date 10/04/16 10:14
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Orm\Abs;

use Phact\Main\Phact;
use Phact\Orm\ConnectionManager;
use Doctrine\DBAL\Query\QueryBuilder as DBALQueryBuilder;
use Doctrine\DBAL\Connection as DBALConnection;
use Phact\Tests\Templates\DatabaseTest;

abstract class AbstractConnectionsTest extends DatabaseTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
* @date 10/04/16 10:14
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Orm\Abs;

use Modules\Test\Models\Note;
use Modules\Test\Models\NoteThesis;
use Phact\Orm\Fields\AutoField;
use Phact\Orm\Fields\CharField;
use Phact\Orm\Fields\ForeignField;
use Phact\Orm\FieldsManager;
use Phact\Tests\Templates\DatabaseTest;

abstract class AbstractFieldsManagerTest extends DatabaseTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @date 10/04/16 10:14
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Orm\Abs;

use Modules\Test\Models\Author;
use Modules\Test\Models\Book;
Expand All @@ -19,6 +19,7 @@
use Modules\Test\Models\Person;
use Modules\Test\Models\Storage;
use Modules\Test\Models\Work;
use Phact\Tests\Templates\DatabaseTest;

abstract class AbstractIntFieldTest extends DatabaseTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @date 10/04/16 10:14
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Orm\Abs;

use Modules\Test\Models\Area;
use Modules\Test\Models\Author;
Expand All @@ -27,6 +27,7 @@
use Phact\Orm\Manager;
use Phact\Orm\Q;
use Phact\Orm\QuerySet;
use Phact\Tests\Templates\DatabaseTest;

abstract class AbstractLookupsTest extends DatabaseTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
* @date 10/04/16 10:14
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Orm\Abs;

use Modules\Test\Models\Author;
use Modules\Test\Models\Blogger;
use Modules\Test\Models\Book;
use Modules\Test\Models\Group;
use Modules\Test\Models\Membership;
use Modules\Test\Models\Person;
use Phact\Tests\Templates\DatabaseTest;

abstract class AbstractManyToManyTest extends DatabaseTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
* @date 10/04/16 10:14
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Orm\Abs;

use Modules\Test\Models\Author;
use Modules\Test\Models\Book;
use Modules\Test\Models\Group;
use Modules\Test\Models\Membership;
use Modules\Test\Models\Person;
use Modules\Test\Models\Work;
use Phact\Tests\Templates\DatabaseTest;

abstract class AbstractModelTest extends DatabaseTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
* @date 10/04/16 10:14
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Orm\Abs;

use Modules\Test\Models\Note;
use Phact\Orm\Query;
use Phact\Tests\Templates\DatabaseTest;

abstract class AbstractQueryLayerTest extends DatabaseTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @date 10/04/16 10:14
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Orm\Abs;

use Modules\Test\Models\Area;
use Modules\Test\Models\Author;
Expand All @@ -20,21 +20,24 @@
use Modules\Test\Models\NotePropertyCharValue;
use Modules\Test\Models\NotePropertyIntValue;
use Modules\Test\Models\NoteThesis;
use Modules\Test\Models\NoteThesisVote;
use Phact\Orm\Aggregations\Avg;
use Phact\Orm\Aggregations\Count;
use Phact\Orm\Expression;
use Phact\Orm\Having\Having;
use Phact\Orm\Manager;
use Phact\Orm\Q;
use Phact\Orm\QuerySet;
use Phact\Tests\Templates\DatabaseTest;

abstract class QuerySetTest extends DatabaseTest
abstract class AbstractQuerySetTest extends DatabaseTest
{
public function useModels()
{
return [
new Note(),
new NoteThesis(),
new NoteThesisVote(),
new Author(),
new Area(),
new Group(),
Expand Down Expand Up @@ -215,6 +218,9 @@ public function testValues()

$sql = Note::objects()->getQuerySet()->filter(['pk' => 1])->valuesSql(['id', 'name', 'theses__name'], false, false);
$this->assertEquals("SELECT {$q}test_note{$q}.{$q}id{$q} AS {$q}id{$q}, {$q}test_note{$q}.{$q}name{$q} AS {$q}name{$q}, {$q}test_note_thesis_1{$q}.{$q}name{$q} AS {$q}theses__name{$q} FROM {$q}test_note{$q} LEFT JOIN {$q}test_note_thesis{$q} {$q}test_note_thesis_1{$q} ON {$q}test_note{$q}.{$q}id{$q} = {$q}test_note_thesis_1{$q}.{$q}note_id{$q} WHERE {$q}test_note{$q}.{$q}id{$q} = 1", $sql);

$sql = NoteThesisVote::objects()->getQuerySet()->filter(['pk' => 1])->valuesSql(['id', 'rating', 'note_thesis__note__name'], false, false);
$this->assertEquals("SELECT {$q}test_note_thesis_vote{$q}.{$q}id{$q} AS {$q}id{$q}, {$q}test_note_thesis_vote{$q}.{$q}rating{$q} AS {$q}rating{$q}, {$q}test_note_2{$q}.{$q}name{$q} AS {$q}note_thesis__note__name{$q} FROM {$q}test_note_thesis_vote{$q} LEFT JOIN {$q}test_note_thesis{$q} {$q}test_note_thesis_1{$q} ON {$q}test_note_thesis_vote{$q}.{$q}note_thesis_id{$q} = {$q}test_note_thesis_1{$q}.{$q}id{$q} LEFT JOIN {$q}test_note{$q} {$q}test_note_2{$q} ON {$q}test_note_thesis_1{$q}.{$q}note_id{$q} = {$q}test_note_2{$q}.{$q}id{$q} WHERE {$q}test_note_thesis_vote{$q}.{$q}id{$q} = 1", $sql);
}

public function testChoices()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @date 10/04/16 10:14
*/

namespace Phact\Tests;
namespace Phact\Tests\Cases\Orm\Abs;

use Modules\Test\Models\Author;
use Modules\Test\Models\Book;
Expand All @@ -21,6 +21,7 @@
use Modules\Test\Models\NoteThesis;
use Modules\Test\Models\Schema;
use Phact\Orm\Fields\HasManyField;
use Phact\Tests\Templates\DatabaseTest;

abstract class AbstractQuotesTest extends DatabaseTest
{
Expand Down
Loading

0 comments on commit c361ac3

Please sign in to comment.