diff --git a/tests/integration/Mvc/Model/UnderscoreGetCest.php b/tests/integration/Mvc/Model/UnderscoreGetCest.php index 05680749539..5225f148bd4 100644 --- a/tests/integration/Mvc/Model/UnderscoreGetCest.php +++ b/tests/integration/Mvc/Model/UnderscoreGetCest.php @@ -37,167 +37,167 @@ public function _after(IntegrationTester $I) $this->container['db']->close(); } -// /** -// * Tests Phalcon\Mvc\Model :: __get() -// * -// * @author Balázs Németh -// * @since 2019-05-07 -// */ -// public function mvcModelUnderscoreGet(IntegrationTester $I) -// { -// $I->wantToTest('Mvc\Model - __get()'); -// -// $user = new Models\Users(); -// -// $user->id = 999; -// $user->name = 'Test'; -// -// $I->assertEquals( -// 999, -// $user->id -// ); -// -// $I->assertEquals( -// 'Test', -// $user->name -// ); -// } -// -// /** -// * Tests Phalcon\Mvc\Model :: __get() whether it is using getters correctly -// * -// * @author Balázs Németh -// * @since 2019-05-07 -// */ -// public function mvcModelUnderscoreGetIsUsingGetters(IntegrationTester $I) -// { -// $I->wantToTest("Mvc\Model - __get() whether it is using getters correctly"); -// -// $model = new Models\Select(); -// $model->setId(123); -// -// $I->assertEquals( -// 123, -// $model->id -// ); -// -// $associativeArray = [ -// 'firstName' => 'First name', -// 'lastName' => 'Last name', -// ]; -// -// $model->setName($associativeArray); -// -// $I->assertEquals( -// $associativeArray, -// $model->name -// ); -// -// $model->setText('MyText'); -// -// $I->assertEquals( -// 'MyText', -// $model->text -// ); -// } -// -// /** -// * Tests Phalcon\Mvc\Model :: __get() related records -// * -// * @author Balázs Németh -// * @since 2019-05-07 -// */ -// public function mvcModelUnderscoreGetRelated(IntegrationTester $I) -// { -// $I->wantToTest('Mvc\Model - __get() related records'); -// -// /** -// * Belongs-to relationship -// */ -// $robotPart = Models\RobotsParts::findFirst(); -// -// $part = $robotPart->part; -// -// $I->assertInstanceOf( -// Models\Parts::class, -// $part -// ); -// -// /** -// * Testing has-one relationship -// */ -// $customer = Models\Customers::findFirst(); -// -// $user = $customer->user; -// -// $I->assertInstanceOf( -// Models\Users::class, -// $user -// ); -// -// /** -// * Has-many relationship -// */ -// $robot = Models\Robots::findFirst(); -// -// $robotParts = $robot->robotsParts; -// -// $I->assertInstanceOf( -// Simple::class, -// $robotParts -// ); -// } -// -// /** -// * Tests Phalcon\Mvc\Model :: __get() dirty related records -// * -// * @author Balázs Németh -// * @since 2019-05-07 -// */ -// public function mvcModelUnderscoreGetDirtyRelated(IntegrationTester $I) -// { -// $I->wantToTest('Mvc\Model - __get() dirty related records'); -// -// $robot = Models\Robots::findFirst(); -// -// /** -// * Fill up the related cache with data -// */ -// $robotsParts = $robot->robotsParts; -// -// $I->assertInstanceOf( -// Simple::class, -// $robotsParts -// ); -// -// /** -// * Add new related records -// */ -// $robot->robotsParts = [ -// new Models\RobotsParts(), -// new Models\RobotsParts(), -// ]; -// -// /** -// * Test if the new records were returned -// */ -// $dirtyRobotsParts = $robot->robotsParts; -// -// $I->assertInternalType( -// 'array', -// $dirtyRobotsParts -// ); -// -// $I->assertCount( -// 2, -// $dirtyRobotsParts -// ); -// -// $I->assertInstanceOf( -// Models\RobotsParts::class, -// $dirtyRobotsParts[0] -// ); -// } + /** + * Tests Phalcon\Mvc\Model :: __get() + * + * @author Balázs Németh + * @since 2019-05-07 + */ + public function mvcModelUnderscoreGet(IntegrationTester $I) + { + $I->wantToTest('Mvc\Model - __get()'); + + $user = new Models\Users(); + + $user->id = 999; + $user->name = 'Test'; + + $I->assertEquals( + 999, + $user->id + ); + + $I->assertEquals( + 'Test', + $user->name + ); + } + + /** + * Tests Phalcon\Mvc\Model :: __get() whether it is using getters correctly + * + * @author Balázs Németh + * @since 2019-05-07 + */ + public function mvcModelUnderscoreGetIsUsingGetters(IntegrationTester $I) + { + $I->wantToTest("Mvc\Model - __get() whether it is using getters correctly"); + + $model = new Models\Select(); + $model->setId(123); + + $I->assertEquals( + 123, + $model->id + ); + + $associativeArray = [ + 'firstName' => 'First name', + 'lastName' => 'Last name', + ]; + + $model->setName($associativeArray); + + $I->assertEquals( + $associativeArray, + $model->name + ); + + $model->setText('MyText'); + + $I->assertEquals( + 'MyText', + $model->text + ); + } + + /** + * Tests Phalcon\Mvc\Model :: __get() related records + * + * @author Balázs Németh + * @since 2019-05-07 + */ + public function mvcModelUnderscoreGetRelated(IntegrationTester $I) + { + $I->wantToTest('Mvc\Model - __get() related records'); + + /** + * Belongs-to relationship + */ + $robotPart = Models\RobotsParts::findFirst(); + + $part = $robotPart->part; + + $I->assertInstanceOf( + Models\Parts::class, + $part + ); + + /** + * Testing has-one relationship + */ + $customer = Models\Customers::findFirst(); + + $user = $customer->user; + + $I->assertInstanceOf( + Models\Users::class, + $user + ); + + /** + * Has-many relationship + */ + $robot = Models\Robots::findFirst(); + + $robotParts = $robot->robotsParts; + + $I->assertInstanceOf( + Simple::class, + $robotParts + ); + } + + /** + * Tests Phalcon\Mvc\Model :: __get() dirty related records + * + * @author Balázs Németh + * @since 2019-05-07 + */ + public function mvcModelUnderscoreGetDirtyRelated(IntegrationTester $I) + { + $I->wantToTest('Mvc\Model - __get() dirty related records'); + + $robot = Models\Robots::findFirst(); + + /** + * Fill up the related cache with data + */ + $robotsParts = $robot->robotsParts; + + $I->assertInstanceOf( + Simple::class, + $robotsParts + ); + + /** + * Add new related records + */ + $robot->robotsParts = [ + new Models\RobotsParts(), + new Models\RobotsParts(), + ]; + + /** + * Test if the new records were returned + */ + $dirtyRobotsParts = $robot->robotsParts; + + $I->assertInternalType( + 'array', + $dirtyRobotsParts + ); + + $I->assertCount( + 2, + $dirtyRobotsParts + ); + + $I->assertInstanceOf( + Models\RobotsParts::class, + $dirtyRobotsParts[0] + ); + } /** * Tests Phalcon\Mvc\Model :: __get() private property