Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native iterators for Phalcon\Validation\Message\Group #1657

Merged
merged 2 commits into from Dec 9, 2013
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Test case
  • Loading branch information
sjinks committed Dec 9, 2013
commit c55ac8f9817a83c4bac72c08631c25f56313b994
103 changes: 103 additions & 0 deletions ext/tests/issue-1657.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
--TEST--
Use native iterators for Phalcon\Validation\Message\Group - https://github.com/phalcon/cphalcon/pull/1657
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php

class MyGroup extends \Phalcon\Validation\Message\Group
{
public function rewind()
{
echo __METHOD__, PHP_EOL;
return parent::rewind();
}

public function valid()
{
echo __METHOD__, PHP_EOL;
return parent::valid();
}

public function current()
{
echo __METHOD__, PHP_EOL;
return parent::current();
}

public function next()
{
echo __METHOD__, PHP_EOL;
return parent::next();
}
}

$messages = array(
new \Phalcon\Validation\Message("Message 1"),
new \Phalcon\Validation\Message("Message 2"),
new \Phalcon\Validation\Message("Message 3"),
);

$group = new \Phalcon\Validation\Message\Group($messages);
// Native Iterator Interface is used here
foreach ($group as $msg) {
var_dump($msg->getMessage());
}

// Class methods are used here
$group->rewind();
while ($group->valid()) {
$msg = $group->current();
var_dump($msg->getMessage());
$group->next();
}

// Inherited class - userspace methods are invoked
$group = new \MyGroup($messages);
foreach ($group as $msg) {
var_dump($msg->getMessage());
}

// Inherited class - userspace methods are invoked
$group->rewind();
while ($group->valid()) {
$msg = $group->current();
var_dump($msg->getMessage());
$group->next();
}
?>
--EXPECT--
string(9) "Message 1"
string(9) "Message 2"
string(9) "Message 3"
string(9) "Message 1"
string(9) "Message 2"
string(9) "Message 3"
MyGroup::rewind
MyGroup::valid
MyGroup::current
string(9) "Message 1"
MyGroup::next
MyGroup::valid
MyGroup::current
string(9) "Message 2"
MyGroup::next
MyGroup::valid
MyGroup::current
string(9) "Message 3"
MyGroup::next
MyGroup::valid
MyGroup::rewind
MyGroup::valid
MyGroup::current
string(9) "Message 1"
MyGroup::next
MyGroup::valid
MyGroup::current
string(9) "Message 2"
MyGroup::next
MyGroup::valid
MyGroup::current
string(9) "Message 3"
MyGroup::next
MyGroup::valid