Добавлен цикл проверки сайтов

This commit is contained in:
2024-08-12 15:14:49 +03:00
parent 0b56cd37b5
commit 6b7199a326
115 changed files with 15964 additions and 88 deletions

View File

@ -0,0 +1,74 @@
<?php
/**
* Author: Nil Portugués Calderó <contact@nilportugues.com>
* Date: 6/7/14
* Time: 11:44 PM.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NilPortugues\Tests\Sql\QueryBuilder\Manipulation;
/**
* Class BaseQueryTest.
*/
class BaseQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \NilPortugues\Tests\Sql\QueryBuilder\Manipulation\Resources\DummyQuery
*/
private $query;
/**
* @var string
*/
private $whereClass = '\NilPortugues\Sql\QueryBuilder\Syntax\Where';
/**
*
*/
protected function setUp()
{
$this->query = new Resources\DummyQuery();
$this->query->setTable('tablename');
}
/**
*
*/
protected function tearDown()
{
$this->query = null;
}
/**
* @test
*/
public function itShouldBeAbleToSetTableName()
{
$this->assertSame('tablename', $this->query->getTable()->getName());
}
/**
* @test
*/
public function itShouldGetWhere()
{
$this->assertNull($this->query->getWhere());
$this->query->where();
$this->assertInstanceOf($this->whereClass, $this->query->getWhere());
}
/**
* @test
*/
public function itShouldGetWhereOperator()
{
$this->assertSame('AND', $this->query->getWhereOperator());
$this->query->where('OR');
$this->assertSame('OR', $this->query->getWhereOperator());
}
}

View File

@ -0,0 +1,56 @@
<?php
/**
* Author: Nil Portugués Calderó <contact@nilportugues.com>
* Date: 6/3/14
* Time: 1:37 AM.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NilPortugues\Tests\Sql\QueryBuilder\Manipulation;
use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder;
use NilPortugues\Sql\QueryBuilder\Manipulation\Delete;
/**
* Class DeleteTest.
*/
class DeleteTest extends \PHPUnit_Framework_TestCase
{
/**
* @var GenericBuilder
*/
private $writer;
/**
* @var Delete
*/
private $query;
/**
*
*/
protected function setUp()
{
$this->query = new Delete();
}
/**
* @test
*/
public function itShouldGetPartName()
{
$this->assertSame('DELETE', $this->query->partName());
}
/**
* @test
*/
public function itShouldReturnLimit1()
{
$this->query->limit(1);
$this->assertSame(1, $this->query->getLimitStart());
}
}

View File

@ -0,0 +1,77 @@
<?php
/**
* Author: Nil Portugués Calderó <contact@nilportugues.com>
* Date: 6/3/14
* Time: 1:37 AM.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NilPortugues\Tests\Sql\QueryBuilder\Manipulation;
use NilPortugues\Sql\QueryBuilder\Manipulation\Insert;
/**
* Class InsertTest.
*/
class InsertTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Insert
*/
private $query;
/**
*
*/
protected function setUp()
{
$this->query = new Insert();
}
/**
* @test
*/
public function itShouldGetPartName()
{
$this->assertSame('INSERT', $this->query->partName());
}
/**
* @test
*/
public function itShouldSetValues()
{
$values = ['user_id' => 1, 'username' => 'nilportugues'];
$this->query->setValues($values);
$this->assertSame($values, $this->query->getValues());
}
/**
* @test
*/
public function itShouldGetColumns()
{
$values = ['user_id' => 1, 'username' => 'nilportugues'];
$this->query->setValues($values);
$columns = $this->query->getColumns();
$this->assertInstanceOf('NilPortugues\Sql\QueryBuilder\Syntax\Column', $columns[0]);
}
/**
* @test
*/
public function itShouldSetNullableValues()
{
$values = ['user_id' => 1, 'description' => null, 'isVisible' => false];
$this->query->setValues($values);
$this->assertSame($values, $this->query->getValues());
}
}

View File

@ -0,0 +1,89 @@
<?php
/**
* Author: Nil Portugués Calderó <contact@nilportugues.com>
* Date: 9/12/14
* Time: 7:26 PM.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NilPortugues\Tests\Sql\QueryBuilder\Manipulation;
use NilPortugues\Sql\QueryBuilder\Manipulation\Intersect;
use NilPortugues\Sql\QueryBuilder\Manipulation\Select;
/**
* Class IntersectTest.
*/
class IntersectTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Intersect
*/
private $query;
/**
* @var string
*/
private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException';
/**
*
*/
protected function setUp()
{
$this->query = new Intersect();
}
/**
* @test
*/
public function itShouldGetPartName()
{
$this->assertSame('INTERSECT', $this->query->partName());
}
/**
* @test
*/
public function itShouldThrowExceptionForUnsupportedGetTable()
{
$this->setExpectedException($this->exceptionClass);
$this->query->getTable();
}
/**
* @test
*/
public function itShouldThrowExceptionForUnsupportedGetWhere()
{
$this->setExpectedException($this->exceptionClass);
$this->query->getWhere();
}
/**
* @test
*/
public function itShouldThrowExceptionForUnsupportedWhere()
{
$this->setExpectedException($this->exceptionClass);
$this->query->where();
}
/**
* @test
*/
public function itShouldGetIntersectSelects()
{
$this->assertEquals(array(), $this->query->getIntersects());
$select1 = new Select('user');
$select2 = new Select('user_email');
$this->query->add($select1);
$this->query->add($select2);
$this->assertEquals(array($select1, $select2), $this->query->getIntersects());
}
}

View File

@ -0,0 +1,82 @@
<?php
/**
* Author: Nil Portugués Calderó <contact@nilportugues.com>
* Date: 9/12/14
* Time: 7:26 PM.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NilPortugues\Tests\Sql\QueryBuilder\Manipulation;
use NilPortugues\Sql\QueryBuilder\Manipulation\Minus;
use NilPortugues\Sql\QueryBuilder\Manipulation\Select;
/**
* Class MinusTest.
*/
class MinusTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Minus
*/
private $query;
/**
* @var string
*/
private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException';
/**
*
*/
protected function setUp()
{
$this->query = new Minus(new Select('user'), new Select('user_email'));
}
/**
* @test
*/
public function itShouldGetPartName()
{
$this->assertSame('MINUS', $this->query->partName());
}
/**
* @test
*/
public function itShouldThrowExceptionForUnsupportedGetTable()
{
$this->setExpectedException($this->exceptionClass);
$this->query->getTable();
}
/**
* @test
*/
public function itShouldThrowExceptionForUnsupportedGetWhere()
{
$this->setExpectedException($this->exceptionClass);
$this->query->getWhere();
}
/**
* @test
*/
public function itShouldThrowExceptionForUnsupportedWhere()
{
$this->setExpectedException($this->exceptionClass);
$this->query->where();
}
/**
* @test
*/
public function itShouldGetMinusSelects()
{
$this->assertEquals(new Select('user'), $this->query->getFirst());
$this->assertEquals(new Select('user_email'), $this->query->getSecond());
}
}

View File

@ -0,0 +1,98 @@
<?php
/**
* Author: Nil Portugués Calderó <contact@nilportugues.com>
* Date: 6/16/14
* Time: 8:50 PM.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NilPortugues\Tests\Sql\QueryBuilder\Manipulation;
use NilPortugues\Sql\QueryBuilder\Manipulation\QueryFactory;
use NilPortugues\Sql\QueryBuilder\Manipulation\Select;
/**
* Class QueryFactoryTest.
*/
class QueryFactoryTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function itShouldCreateSelectObject()
{
$className = '\NilPortugues\Sql\QueryBuilder\Manipulation\Select';
$this->assertInstanceOf($className, QueryFactory::createSelect());
}
/**
* @test
*/
public function itShouldCreateInsertObject()
{
$className = '\NilPortugues\Sql\QueryBuilder\Manipulation\Insert';
$this->assertInstanceOf($className, QueryFactory::createInsert());
}
/**
* @test
*/
public function itShouldCreateUpdateObject()
{
$className = '\NilPortugues\Sql\QueryBuilder\Manipulation\Update';
$this->assertInstanceOf($className, QueryFactory::createUpdate());
}
/**
* @test
*/
public function itShouldCreateDeleteObject()
{
$className = '\NilPortugues\Sql\QueryBuilder\Manipulation\Delete';
$this->assertInstanceOf($className, QueryFactory::createDelete());
}
/**
* @test
*/
public function itShouldCreateMinusObject()
{
$className = '\NilPortugues\Sql\QueryBuilder\Manipulation\Minus';
$this->assertInstanceOf($className, QueryFactory::createMinus(new Select('table1'), new Select('table2')));
}
/**
* @test
*/
public function itShouldCreateUnionObject()
{
$className = '\NilPortugues\Sql\QueryBuilder\Manipulation\Union';
$this->assertInstanceOf($className, QueryFactory::createUnion());
}
/**
* @test
*/
public function itShouldCreateUnionAllObject()
{
$className = '\NilPortugues\Sql\QueryBuilder\Manipulation\UnionAll';
$this->assertInstanceOf($className, QueryFactory::createUnionAll());
}
/**
* @test
*/
public function itShouldCreateWhereObject()
{
$mockClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryInterface';
$query = $this->getMockBuilder($mockClass)
->disableOriginalConstructor()
->getMock();
$className = '\NilPortugues\Sql\QueryBuilder\Syntax\Where';
$this->assertInstanceOf($className, QueryFactory::createWhere($query));
}
}

View File

@ -0,0 +1,27 @@
<?php
/**
* Author: Nil Portugués Calderó <contact@nilportugues.com>
* Date: 6/3/14
* Time: 12:58 AM.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NilPortugues\Tests\Sql\QueryBuilder\Manipulation\Resources;
use NilPortugues\Sql\QueryBuilder\Manipulation\AbstractBaseQuery;
/**
* Class DummyQuery.
*/
class DummyQuery extends AbstractBaseQuery
{
/**
* @return string
*/
public function partName()
{
return 'DUMMY';
}
}

View File

@ -0,0 +1,101 @@
<?php
/**
* Author: Nil Portugués Calderó <contact@nilportugues.com>
* Date: 6/3/14
* Time: 1:36 AM.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NilPortugues\Tests\Sql\QueryBuilder\Manipulation;
use NilPortugues\Sql\QueryBuilder\Manipulation\Select;
use NilPortugues\Sql\QueryBuilder\Syntax\OrderBy;
/**
* Class SelectTest.
*/
class SelectTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Select
*/
private $query;
/**
*
*/
protected function setUp()
{
$this->query = new Select();
}
/**
* @test
*/
public function itShouldGetPartName()
{
$this->assertSame('SELECT', $this->query->partName());
}
/**
* @test
*/
public function itShouldSetParentOrderByAlso()
{
$columns = [
'id',
'phase_id',
'league_id',
'date',
];
$parentTable = 'events';
$this->query->setTable($parentTable);
$this->query->setColumns($columns);
$sorts = [
[
'field' => 'league_id',
'direction' => 1,
],
[
'field' => 'start_date',
'direction' => 0,
'table' => 'phases',
'joinBy' => 'phase_id',
'joinWith' => 'id',
],
[
'field' => 'date',
'direction' => 1,
],
];
if (is_array($sorts)) {
foreach ($sorts as $sort) {
$order = (int)$sort['direction'] > 0 ? OrderBy::ASC : OrderBy::DESC;
if (count($sort) == 5) {
$this->query->leftJoin(
$sort['table'],
$sort['joinBy'],
$sort['joinWith']
)->orderBy($sort['field'], $order);
} else {
$this->query->orderBy($sort['field'], $order);
}
}
}
$returnedOrders = $this->query->getAllOrderBy();
foreach ($returnedOrders as $id => $orderByObject) {
$column = $orderByObject->getColumn();
$table = $column->getTable();
$expectedColumn = $sorts[$id]['field'];
$expectedTable = array_key_exists('table', $sorts[$id]) ? $sorts[$id]['table'] : $parentTable;
$expectedDirection = (int)$sorts[$id]['direction'] > 0 ? OrderBy::ASC : OrderBy::DESC;
$this->assertSame($expectedColumn, $column->getName());
$this->assertSame($expectedTable, $table->getName());
$this->assertSame($expectedDirection, $orderByObject->getDirection());
}
$this->assertCount(count($sorts), $returnedOrders);
}
}

View File

@ -0,0 +1,89 @@
<?php
/**
* Author: Nil Portugués Calderó <contact@nilportugues.com>
* Date: 9/12/14
* Time: 7:26 PM.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NilPortugues\Tests\Sql\QueryBuilder\Manipulation;
use NilPortugues\Sql\QueryBuilder\Manipulation\UnionAll;
use NilPortugues\Sql\QueryBuilder\Manipulation\Select;
/**
* Class UnionAllTest.
*/
class UnionAllTest extends \PHPUnit_Framework_TestCase
{
/**
* @var UnionAll
*/
private $query;
/**
* @var string
*/
private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException';
/**
*
*/
protected function setUp()
{
$this->query = new UnionAll();
}
/**
* @test
*/
public function itShouldGetPartName()
{
$this->assertSame('UNION ALL', $this->query->partName());
}
/**
* @test
*/
public function itShouldThrowExceptionForUnsupportedGetTable()
{
$this->setExpectedException($this->exceptionClass);
$this->query->getTable();
}
/**
* @test
*/
public function itShouldThrowExceptionForUnsupportedGetWhere()
{
$this->setExpectedException($this->exceptionClass);
$this->query->getWhere();
}
/**
* @test
*/
public function itShouldThrowExceptionForUnsupportedWhere()
{
$this->setExpectedException($this->exceptionClass);
$this->query->where();
}
/**
* @test
*/
public function itShouldGetIntersectSelects()
{
$this->assertEquals(array(), $this->query->getUnions());
$select1 = new Select('user');
$select2 = new Select('user_email');
$this->query->add($select1);
$this->query->add($select2);
$this->assertEquals(array($select1, $select2), $this->query->getUnions());
}
}

View File

@ -0,0 +1,89 @@
<?php
/**
* Author: Nil Portugués Calderó <contact@nilportugues.com>
* Date: 9/12/14
* Time: 7:26 PM.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NilPortugues\Tests\Sql\QueryBuilder\Manipulation;
use NilPortugues\Sql\QueryBuilder\Manipulation\Union;
use NilPortugues\Sql\QueryBuilder\Manipulation\Select;
/**
* Class UnionTest.
*/
class UnionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Union
*/
private $query;
/**
* @var string
*/
private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException';
/**
*
*/
protected function setUp()
{
$this->query = new Union();
}
/**
* @test
*/
public function itShouldGetPartName()
{
$this->assertSame('UNION', $this->query->partName());
}
/**
* @test
*/
public function itShouldThrowExceptionForUnsupportedGetTable()
{
$this->setExpectedException($this->exceptionClass);
$this->query->getTable();
}
/**
* @test
*/
public function itShouldThrowExceptionForUnsupportedGetWhere()
{
$this->setExpectedException($this->exceptionClass);
$this->query->getWhere();
}
/**
* @test
*/
public function itShouldThrowExceptionForUnsupportedWhere()
{
$this->setExpectedException($this->exceptionClass);
$this->query->where();
}
/**
* @test
*/
public function itShouldGetIntersectSelects()
{
$this->assertEquals(array(), $this->query->getUnions());
$select1 = new Select('user');
$select2 = new Select('user_email');
$this->query->add($select1);
$this->query->add($select2);
$this->assertEquals(array($select1, $select2), $this->query->getUnions());
}
}

View File

@ -0,0 +1,73 @@
<?php
/**
* Author: Nil Portugués Calderó <contact@nilportugues.com>
* Date: 6/3/14
* Time: 1:37 AM.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NilPortugues\Tests\Sql\QueryBuilder\Manipulation;
use NilPortugues\Sql\QueryBuilder\Manipulation\Update;
/**
* Class UpdateTest.
*/
class UpdateTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Update
*/
private $query;
/**
*
*/
protected function setUp()
{
$this->query = new Update();
}
/**
* @test
*/
public function itShouldGetPartName()
{
$this->assertSame('UPDATE', $this->query->partName());
}
/**
* @test
*/
public function itShouldReturnLimit1()
{
$this->query->limit(1);
$this->assertSame(1, $this->query->getLimitStart());
}
/**
* @test
*/
public function itShouldReturnValues()
{
$values = ['user_id' => 1];
$this->query->setValues($values);
$this->assertSame($values, $this->query->getValues());
}
/**
* @test
*/
public function itShouldSetNullableValues()
{
$values = ['user_id' => 1, 'description' => null, 'isVisible' => false];
$this->query->setValues($values);
$this->assertSame($values, $this->query->getValues());
}
}