Commit daebb598 by Russell Belfer

Add PHP tests and fix bug in PHP builtin driver

parent 082e82db
......@@ -186,7 +186,7 @@ PATTERNS("csharp",
"|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
PATTERNS("php",
"^[ \t]*((public|private|protected|static|final)[ \t]+)*((class|function)[ \t].*)$",
"^[ \t]*(((public|private|protected|static|final)[ \t]+)*((class|function)[ \t].*))$",
/* -- */
"[a-zA-Z_][a-zA-Z0-9_]*"
"|[-+0-9.e]+[fFlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
......
802734c801bffc466d69876bc4814f747aaac4fe refs/heads/master
60e3f7b244a5305e2c9fa4ef0e897f3b14f3b8dd refs/heads/master
P pack-03f78c35e3ca74fffd9d6c2b6dcd60d6ab6a614a.pack
P pack-1652578900ac63564f2a24b9714529821276ceb9.pack
# pack-refs with: peeled fully-peeled
802734c801bffc466d69876bc4814f747aaac4fe refs/heads/master
60e3f7b244a5305e2c9fa4ef0e897f3b14f3b8dd refs/heads/master
<?php
namespace Faker;
/**
* Proxy for other generators, to return only unique values. Works with
* Faker\Generator\Base->unique()
*/
class UniqueGenerator
{
protected $generator;
protected $maxRetries;
protected $moreStuff;
protected $uniques = array();
public function __construct(Generator $generator, $maxRetries)
{
$this->generator = $generator;
$this->maxRetries = $maxRetries + 1;
}
/**
* Catch and proxy all generator calls but return only unique values
*/
public function __get($attribute)
{
return $this->__call($attribute, array());
}
/**
* Catch and proxy all generator calls with arguments but return only unique values
*/
public function __call($name, $arguments)
{
$i = 0;
if (!isset($this->uniques[$name])) {
$this->uniques[$name] = array();
}
do {
$res = call_user_func_array(array($this->generator, $name), $arguments);
$i++;
if ($i >= $this->maxRetries) {
throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries));
}
} while (in_array($res, $this->uniques[$name]));
$this->uniques[$name][]= $res;
return $res;
}
}
<?php
namespace Faker;
/**
* Proxy for other generators, to return only unique values. Works with
* Faker\Generator\Base->unique()
*/
class UniqueGenerator
{
protected $generator;
protected $maxRetries;
protected $uniques = array();
public function __construct(Generator $generator, $maxRetries)
{
$this->generator = $generator;
$this->maxRetries = $maxRetries;
}
/**
* Catch and proxy all generator calls but return only unique values
*/
public function __get($attribute)
{
return $this->__call($attribute, array());
}
/**
* Catch and proxy all generator calls with arguments but return only unique values
*/
public function __call($name, $arguments)
{
if (!isset($this->uniques[$name])) {
$this->uniques[$name] = array();
}
$i = 0;
do {
$res = call_user_func_array(array($this->generator, $name), $arguments);
$i++;
if ($i > $this->maxRetries) {
throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries));
}
} while (in_array($res, $this->uniques[$name]));
$this->uniques[$name][]= $res;
return $res;
}
}
diff --git a/files/file.php b/files/file.php
index 63250ad..967d646 100644
--- a/files/file.php
+++ b/files/file.php
@@ -12,2 +12,3 @@ class UniqueGenerator
protected $maxRetries;
+ protected $moreStuff;
protected $uniques = array();
@@ -17,3 +18,3 @@ public function __construct(Generator $generator, $maxRetries)
$this->generator = $generator;
- $this->maxRetries = $maxRetries;
+ $this->maxRetries = $maxRetries + 1;
}
@@ -33,10 +34,10 @@ public function __call($name, $arguments)
{
+ $i = 0;
if (!isset($this->uniques[$name])) {
$this->uniques[$name] = array();
}
- $i = 0;
do {
$res = call_user_func_array(array($this->generator, $name), $arguments);
$i++;
- if ($i > $this->maxRetries) {
+ if ($i >= $this->maxRetries) {
throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries));
diff --git a/files/file.php b/files/file.php
index 63250ad..967d646 100644
--- a/files/file.php
+++ b/files/file.php
@@ -12,2 +12,3 @@ class UniqueGenerator
protected $maxRetries;
+ protected $moreStuff;
protected $uniques = array();
@@ -17,3 +18,3 @@ class UniqueGenerator
$this->generator = $generator;
- $this->maxRetries = $maxRetries;
+ $this->maxRetries = $maxRetries + 1;
}
@@ -33,10 +34,10 @@ class UniqueGenerator
{
+ $i = 0;
if (!isset($this->uniques[$name])) {
$this->uniques[$name] = array();
}
- $i = 0;
do {
$res = call_user_func_array(array($this->generator, $name), $arguments);
$i++;
- if ($i > $this->maxRetries) {
+ if ($i >= $this->maxRetries) {
throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries));
<?php
namespace Faker;
/**
* Proxy for other generators, to return only unique values. Works with
* Faker\Generator\Base->unique()
*/
class UniqueGenerator
{
protected $generator;
protected $maxRetries;
protected $moreStuff;
protected $uniques = array();
public function __construct(Generator $generator, $maxRetries)
{
$this->generator = $generator;
$this->maxRetries = $maxRetries + 1;
}
/**
* Catch and proxy all generator calls but return only unique values
*/
public function __get($attribute)
{
return $this->__call($attribute, array());
}
/**
* Catch and proxy all generator calls with arguments but return only unique values
*/
public function __call($name, $arguments)
{
$i = 0;
if (!isset($this->uniques[$name])) {
$this->uniques[$name] = array();
}
do {
$res = call_user_func_array(array($this->generator, $name), $arguments);
$i++;
if ($i >= $this->maxRetries) {
throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries));
}
} while (in_array($res, $this->uniques[$name]));
$this->uniques[$name][]= $res;
return $res;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment