Skip to content

Commit

Permalink
Tests ready for issue phalcon#14021
Browse files Browse the repository at this point in the history
  • Loading branch information
Németh Balázs committed May 2, 2019
1 parent d1bd98d commit 4306667
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 30 deletions.
3 changes: 0 additions & 3 deletions tests/_data/fixtures/models/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,4 @@ class Users extends Model
{
public $id;
public $name;

public $firstname;
public $lastname;
}
43 changes: 29 additions & 14 deletions tests/integration/Mvc/Model/UnderscoreSetCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ public function mvcModelUnderscoreSet(IntegrationTester $I)
*
* @param IntegrationTester $I
*
* @see https://github.com/phalcon/cphalcon/issues/14021
*
* @author Balázs Németh <https://github.com/zsilbi>
* @since 2019-05-02
*/
Expand All @@ -84,25 +82,42 @@ public function mvcModelUnderscoreSetWithAssociativeArray(IntegrationTester $I)
$user->id = 999;
$user->name = $associativeArray;


$I->assertEquals(
$associativeArray,
$user->name
[
'id' => 999,
'name' => $associativeArray
],
$user->toArray()
);
}

/**
* Tests Phalcon\Mvc\Model :: __set() undefined property with associative array
*
* @param IntegrationTester $I
*
* @see https://github.com/phalcon/cphalcon/issues/14021
*
* @author Balázs Németh <https://github.com/zsilbi>
* @since 2019-05-02
*/
public function mvcModelUnderscoreSetUndefinedPropertyWithAssociativeArray(IntegrationTester $I)
{
$I->wantToTest('Tests Mvc\Model - __set() undefined property with associative array');

foreach($associativeArray as $key => $value) {
$I->assertNull(
$user->readAttribute($key)
);
$associativeArray = [
'id' => 123,
'name' => 'My Name'
];

$I->assertNull(
$user->readAttribute(strtolower($key))
);
}
$user = new Users();
$user->whatEverUndefinedProperty = $associativeArray;

$I->assertEquals(
[
'id' => 999,
'name' => $associativeArray
'id' => null,
'name' => null
],
$user->toArray()
);
Expand Down
44 changes: 31 additions & 13 deletions tests/integration/Mvc/Model/WriteAttributeCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,11 @@ public function mvcModelWriteAttribute(IntegrationTester $I)
);
}


/**
* Tests Phalcon\Mvc\Model :: writeAttribute() with associative array
*
* @param IntegrationTester $I
*
* @see https://github.com/phalcon/cphalcon/issues/14021
*
* @author Balázs Németh <https://github.com/zsilbi>
* @since 2019-04-30
*/
Expand All @@ -94,16 +91,6 @@ public function mvcModelWriteAttributeWithAssociativeArray(IntegrationTester $I)
$user->readAttribute('name')
);

foreach($associativeArray as $key => $value) {
$I->assertNull(
$user->readAttribute($key)
);

$I->assertNull(
$user->readAttribute(strtolower($key))
);
}

$I->assertEquals(
[
'id' => 123,
Expand All @@ -112,4 +99,35 @@ public function mvcModelWriteAttributeWithAssociativeArray(IntegrationTester $I)
$user->toArray()
);
}

/**
* Tests Phalcon\Mvc\Model :: writeAttribute() undefined property with associative array
*
* @param IntegrationTester $I
*
* @see https://github.com/phalcon/cphalcon/issues/14021
*
* @author Balázs Németh <https://github.com/zsilbi>
* @since 2019-04-30
*/
public function mvcModelWriteAttributeUndefinedPropertyWithAssociativeArray(IntegrationTester $I)
{
$I->wantToTest('Tests Phalcon\Mvc\Model :: writeAttribute() undefined property with associative array');

$associativeArray = [
'id' => 123,
'name' => 'My Name'
];

$user = new Users();
$user->whatEverUndefinedProperty = $associativeArray;

$I->assertEquals(
[
'id' => null,
'name' => null
],
$user->toArray()
);
}
}

0 comments on commit 4306667

Please sign in to comment.