Skip to content

Commit

Permalink
Use PSR-1 for PHPUnit TestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
carusogabriel authored and chilimatic committed Jan 15, 2018
1 parent a1d17e5 commit 2f12db1
Show file tree
Hide file tree
Showing 24 changed files with 92 additions and 50 deletions.
4 changes: 3 additions & 1 deletion unit-tests/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

require_once 'helpers/xcache.php';

class CacheTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class CacheTest extends TestCase
{

public function setUp()
Expand Down
3 changes: 2 additions & 1 deletion unit-tests/DbBindTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
*/

use Phalcon\Db\Column as DbColumn;
use PHPUnit\Framework\TestCase;

class DbBindTest extends PHPUnit_Framework_TestCase
class DbBindTest extends TestCase
{
public function testDbBindMysql()
{
Expand Down
4 changes: 3 additions & 1 deletion unit-tests/DbDescribeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
+------------------------------------------------------------------------+
*/

class DbDescribeTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class DbDescribeTest extends TestCase
{

public function getExpectedColumnsMysql()
Expand Down
4 changes: 3 additions & 1 deletion unit-tests/DbProfilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
+------------------------------------------------------------------------+
*/

use PHPUnit\Framework\TestCase;

class DbProfiler extends Phalcon\Db\Profiler
{

Expand Down Expand Up @@ -71,7 +73,7 @@ public function getProfiler()

}

class DbProfilerTest extends PHPUnit_Framework_TestCase
class DbProfilerTest extends TestCase
{

public function testDbMysql()
Expand Down
4 changes: 3 additions & 1 deletion unit-tests/DbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
+------------------------------------------------------------------------+
*/

class DbTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class DbTest extends TestCase
{
/**
* @medium
Expand Down
5 changes: 3 additions & 2 deletions unit-tests/FormsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
Phalcon\Validation\Validator\PresenceOf,
Phalcon\Validation\Validator\StringLength,
Phalcon\Validation\Validator\Regex,
Phalcon\Validation\Message;
Phalcon\Validation\Message,
PHPUnit\Framework\TestCase;

class ContactFormPublicProperties
{
Expand Down Expand Up @@ -61,7 +62,7 @@ public function setAddress($address)
}
}

class FormsTest extends PHPUnit_Framework_TestCase
class FormsTest extends TestCase
{

public function setUp()
Expand Down
4 changes: 3 additions & 1 deletion unit-tests/MicroMvcCollectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
+------------------------------------------------------------------------+
*/

use PHPUnit\Framework\TestCase;

class PersonasController
{
protected $_entered = 0;
Expand Down Expand Up @@ -58,7 +60,7 @@ public static function getEntered()
}
}

class MicroMvcCollectionsTest extends PHPUnit_Framework_TestCase
class MicroMvcCollectionsTest extends TestCase
{

public function testMicroCollections()
Expand Down
4 changes: 3 additions & 1 deletion unit-tests/ModelsCalculationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
+------------------------------------------------------------------------+
*/

class ModelsCalculationsTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class ModelsCalculationsTest extends TestCase
{

public function __construct()
Expand Down
8 changes: 5 additions & 3 deletions unit-tests/ModelsEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
+------------------------------------------------------------------------+
*/

class ModelsEventsTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class ModelsEventsTest extends TestCase
{

public function __construct()
Expand Down Expand Up @@ -123,7 +125,7 @@ public function testEventsCreate()

$this->assertEquals($trace, array(
'prepareSave' => array(
'GossipRobots' => 1
'GossipRobots' => 1
),
'beforeValidation' => array(
'GossipRobots' => 2,
Expand Down Expand Up @@ -170,7 +172,7 @@ public function testEventsUpdate()

$this->assertEquals($trace, array(
'prepareSave' => array(
'GossipRobots' => 1
'GossipRobots' => 1
),
'beforeValidation' => array(
'GossipRobots' => 2,
Expand Down
4 changes: 3 additions & 1 deletion unit-tests/ModelsForeignKeysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
+------------------------------------------------------------------------+
*/

class ModelsForeignKeysTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class ModelsForeignKeysTest extends TestCase
{

public function __construct()
Expand Down
4 changes: 3 additions & 1 deletion unit-tests/ModelsHydrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
+------------------------------------------------------------------------+
*/

class ModelsHydrationTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class ModelsHydrationTest extends TestCase
{

public function __construct()
Expand Down
4 changes: 3 additions & 1 deletion unit-tests/ModelsMetadataStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
+------------------------------------------------------------------------+
*/

class ModelsMetadataStrategyTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class ModelsMetadataStrategyTest extends TestCase
{

protected $_expectedMeta = array(
Expand Down
4 changes: 3 additions & 1 deletion unit-tests/ModelsMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
+------------------------------------------------------------------------+
*/

class ModelsMetadataTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class ModelsMetadataTest extends TestCase
{

public function __construct()
Expand Down
4 changes: 3 additions & 1 deletion unit-tests/ModelsMultipleSourcesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
+------------------------------------------------------------------------+
*/

class ModelsMultipleSourcesTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class ModelsMultipleSourcesTest extends TestCase
{

public function __construct()
Expand Down
3 changes: 2 additions & 1 deletion unit-tests/ModelsQueryExecuteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
*/

use Phalcon\Mvc\Model\Query as Query;
use PHPUnit\Framework\TestCase;

class ModelsQueryExecuteTest extends PHPUnit_Framework_TestCase
class ModelsQueryExecuteTest extends TestCase
{

public function __construct()
Expand Down
4 changes: 3 additions & 1 deletion unit-tests/ModelsRelationsMagicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
+------------------------------------------------------------------------+
*/

class ModelsRelationsMagicTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class ModelsRelationsMagicTest extends TestCase
{

public function __construct()
Expand Down
4 changes: 3 additions & 1 deletion unit-tests/ModelsRelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
+------------------------------------------------------------------------+
*/

class ModelsRelationsTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class ModelsRelationsTest extends TestCase
{

public function __construct()
Expand Down
4 changes: 3 additions & 1 deletion unit-tests/ModelsResultsetCacheStaticTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
+------------------------------------------------------------------------+
*/

class ModelsResultsetCacheStaticTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class ModelsResultsetCacheStaticTest extends TestCase
{

public function __construct()
Expand Down
4 changes: 3 additions & 1 deletion unit-tests/ModelsResultsetCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
+------------------------------------------------------------------------+
*/

class ModelsResultsetCacheTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class ModelsResultsetCacheTest extends TestCase
{

public function __construct()
Expand Down
48 changes: 25 additions & 23 deletions unit-tests/ModelsResultsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
+------------------------------------------------------------------------+
*/

class ModelsResultsetTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class ModelsResultsetTest extends TestCase
{

public function __construct()
Expand Down Expand Up @@ -542,51 +544,51 @@ public function testResultsetNormalZero()

$this->assertFalse(isset($robots[0]));
}

public function testResultsetAppendIterator()
{
if (!$this->_prepareTestMysql()) {
$this->markTestSkipped("Skipped");
return;
}

// see http://php.net/manual/en/appenditerator.construct.php
$iterator = new \AppendIterator();
$robots_first = Robots::find(array('limit' => 2));
$robots_second = Robots::find(array('limit' => 1, 'offset' => 2));

$robots_first_0 = $robots_first[0];
$robots_first_1 = $robots_first[1];
$robots_second_0 = $robots_second[0];

$iterator->append($robots_first);
$iterator->append($robots_second);

$iterator->rewind();
$this->assertTrue($iterator->valid());
$this->assertEquals($iterator->key(), 0);
$this->assertEquals($iterator->getIteratorIndex(), 0);
$this->assertEquals(get_class($iterator->current()), 'Robots');
$this->assertEquals($robots_first_0->name, $iterator->current()->name);

$iterator->next();
$this->assertTrue($iterator->valid());
$this->assertEquals($iterator->key(), 1);
$this->assertEquals($iterator->getIteratorIndex(), 0);
$this->assertEquals(get_class($iterator->current()), 'Robots');
$this->assertEquals($robots_first_1->name, $iterator->current()->name);

$iterator->next();
$this->assertTrue($iterator->valid());
$this->assertEquals($iterator->key(), 0);
$this->assertEquals($iterator->getIteratorIndex(), 1);
$this->assertEquals(get_class($iterator->current()), 'Robots');
$this->assertEquals($robots_second_0->name, $iterator->current()->name);

$iterator->next();
$this->assertFalse($iterator->valid());
}

public function testBigResultsetIteration() {
if (!$this->_prepareTestSqlite()) {
$this->markTestSkipped("Skipped");
Expand All @@ -597,31 +599,31 @@ public function testBigResultsetIteration() {
$personas = Personas::find(array(
'limit' => 33
));

$this->assertEquals(count($personas), 33);

$this->assertEquals(get_class($personas->getLast()), 'Personas');

// take first object as reference
$persona_first = $personas[0];
$this->assertEquals(get_class($persona_first), 'Personas');

// make sure objects are the same -> object was not recreared
$this->assertSame($personas[0], $persona_first);
$this->assertSame($personas->current(), $persona_first);
$personas->rewind();
$this->assertTrue($personas->valid());
$this->assertSame($personas->current(), $persona_first);

// second element
$personas->next();
$this->assertTrue($personas->valid());
$persona_second = $personas->current();
$this->assertSame($persona_second, $personas[1]);

// move to last element
$this->assertSame($personas->getLast(), $personas[32]);

// invalid element
$personas->seek(33);
$this->assertFalse($personas->valid());
Expand All @@ -633,28 +635,28 @@ public function testBigResultsetIteration() {
catch(Exception $e){
$this->assertEquals($e->getMessage(), 'The index does not exist in the cursor');
}

// roll-back-cursor -> query needs to be reexecuted
// first object was now recreated... different instance, but equal content
$this->assertNotSame($personas[0], $persona_first);
$this->assertEquals($personas[0], $persona_first);
$persona_first = $personas[0];

// toArray also re-executes the query and invalidates internal pointer
$array = $personas->toArray();
$this->assertEquals(count($array), 33);
// internal query is re-executed again and set to first

// internal query is re-executed again and set to first
$this->assertNotSame($personas[0], $persona_first);
$this->assertEquals($personas[0], $persona_first);

// move to second element and validate
$personas->next();
$this->assertTrue($personas->valid());
$this->assertEquals(get_class($personas[1]), 'Personas');
$this->assertSame($personas->current(), $personas[1]);
$this->assertEquals($persona_second, $personas[1]);

// pick some random indices
$this->assertEquals(get_class($personas[12]), 'Personas');
$this->assertEquals(get_class($personas[23]), 'Personas');
Expand Down
Loading

0 comments on commit 2f12db1

Please sign in to comment.