Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/sanmai/coverage100percent'
Browse files Browse the repository at this point in the history
  • Loading branch information
Athari committed Apr 15, 2018
2 parents 23c92d8 + b366dd1 commit 0cfe1bc
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 41 deletions.
1 change: 0 additions & 1 deletion .coveralls.yml
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
src_dir: YaLinqo
14 changes: 10 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ php:
- 5.6
- 7.0
- 7.1
- 7.2
- nightly

matrix:
allow_failures:
- php: nightly

cache:
directories:
- $HOME/.composer

install:
- composer install --dev
- composer install --prefer-dist

script:
- phpunit
- composer validate
- vendor/bin/phpunit --verbose || travis_terminate 1

after_script:
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then vendor/bin/coveralls -v; fi;'
after_success:
- travis_retry php vendor/bin/php-coveralls -v
24 changes: 12 additions & 12 deletions Tests/Unit/EnumerableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1126,15 +1126,15 @@ function testAverage ()
E::from([ 3, 4, 5 ])->average());
$this->assertEquals(
3,
E::from([ 3, '4', '5b', 'a' ])->average());
E::from([ 3, '4', '5', 0 ])->average());

// average (selector)
$this->assertEquals(
(3 * 2 + 0 + 4 * 2 + 1 + 5 * 2 + 2) / 3,
E::from([ 3, 4, 5 ])->average('$v*2+$k'));
$this->assertEquals(
(3 * 2 + 0 + 4 * 2 + 1 + 5 * 2 + 2 + 0 * 2 + 3) / 4,
E::from([ 3, '4', '5b', 'a' ])->average('$v*2+$k'));
E::from([ 3, '4', '5', 0 ])->average('$v*2+$k'));
}

/** @covers YaLinqo\Enumerable::average
Expand All @@ -1158,15 +1158,15 @@ function testCount ()
E::from([ 3, 4, 5 ])->count());
$this->assertEquals(
4,
E::from([ 3, '4', '5b', 'a' ])->count());
E::from([ 3, '4', '5', 0 ])->count());

// count (predicate)
$this->assertEquals(
2,
E::from([ 3, 4, 5 ])->count('$v*2+$k<10'));
$this->assertEquals(
3,
E::from([ 3, '4', '5b', 'a' ])->count('$v*2+$k<10'));
E::from([ 3, '4', '5', 0 ])->count('$v*2+$k<10'));
}

/** @covers YaLinqo\Enumerable::max
Expand All @@ -1184,7 +1184,7 @@ function testMax ()
E::from([ 3, 5, 4 ])->max('$v-$k*3+2')); // 5 4 0
$this->assertEquals(
5,
E::from([ 3, '5b', '4', 'a' ])->max('$v-$k*3+2')); // 5 4 0 -7
E::from([ 3, '5', '4', 0 ])->max('$v-$k*3+2')); // 5 4 0 -7
}

/** @covers YaLinqo\Enumerable::max
Expand Down Expand Up @@ -1212,7 +1212,7 @@ function testMaxBy ()
E::from([ 2, 0, 3, 5, 6 ])->maxBy($compare, '$v+$k')); // 2 1 5 8 10
$this->assertEquals(
7,
E::from([ '5b', 3, 'a', '4' ])->maxBy($compare, '$v+$k')); // 5 4 2 7
E::from([ '5', 3, false, '4' ])->maxBy($compare, '$v+$k')); // 5 4 2 7
}

/** @covers YaLinqo\Enumerable::maxBy
Expand All @@ -1239,7 +1239,7 @@ function testMin ()
E::from([ 3, 5, 4 ])->min('$v-$k*3+2')); // 5 4 0
$this->assertEquals(
-7,
E::from([ 3, '5b', '4', 'a' ])->min('$v-$k*3+2')); // 5 4 0 -7
E::from([ 3, '5', '4', false ])->min('$v-$k*3+2')); // 5 4 0 -7
}

/** @covers YaLinqo\Enumerable::min
Expand Down Expand Up @@ -1267,7 +1267,7 @@ function testMinBy ()
E::from([ 2, 0, 3, 5, 6 ])->minBy($compare, '$v+$k')); // 2 1 5 8 10
$this->assertEquals(
4,
E::from([ '5b', 3, 'a', '4' ])->minBy($compare, '$v+$k')); // 5 4 2 7
E::from([ '5', 3, 0, '4' ])->minBy($compare, '$v+$k')); // 5 4 2 7
}

/** @covers YaLinqo\Enumerable::minBy
Expand All @@ -1292,15 +1292,15 @@ function testSum ()
E::from([ 3, 4, 5 ])->sum());
$this->assertEquals(
12,
E::from([ 3, '4', '5b', 'a' ])->sum());
E::from([ 3, '4', '5', false ])->sum());

// sum (selector)
$this->assertEquals(
3 * 2 + 0 + 4 * 2 + 1 + 5 * 2 + 2,
E::from([ 3, 4, 5 ])->sum('$v*2+$k'));
$this->assertEquals(
3 * 2 + 0 + 4 * 2 + 1 + 5 * 2 + 2 + 0 * 2 + 3,
E::from([ 3, '4', '5b', 'a' ])->sum('$v*2+$k'));
E::from([ 3, '4', '5', null ])->sum('$v*2+$k'));
}

/** @covers YaLinqo\Enumerable::all
Expand Down Expand Up @@ -1546,10 +1546,10 @@ function testUnion ()
E::from([ 1, 2, 3 ])->union([ ]));
$this->assertEnumEquals(
[ 1, 2, 3 ],
E::from([ ])->union([ 1, 2, 3 ]));
E::from([ ])->union([ 1, 2, 3, 3 ]));
$this->assertEnumEquals(
[ 1, 2, 3 ],
E::from([ 1, 2, 3 ])->union([ 1, 2, 3 ]));
E::from([ 1, 2, 3, 3 ])->union([ 1, 2, 3 ]));

$this->assertEnumEquals(
[ 1, 2, 3 ],
Expand Down
1 change: 1 addition & 0 deletions Tests/Unit/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class FunctionsTest extends TestCaseEnumerable
function testInit ()
{
F::init();
$this->assertNotEmpty(F::$identity);
}

function testIdentity ()
Expand Down
9 changes: 9 additions & 0 deletions Tests/Unit/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class UtilsTest extends TestCaseEnumerable
function testInit ()
{
U::init();
$this->assertInstanceOf(\Closure::class, U::createLambda('$v', 'v,k'));
$this->assertInstanceOf(\Closure::class, U::createLambda('$k', 'v,k'));
}

/** @covers YaLinqo\Utils::createLambda
Expand Down Expand Up @@ -106,6 +108,11 @@ function testCreateLambda_lambdaString ()
$f = U::createLambda('($q, $w, $e, $r) ==> { return $w+$e; }', 'a,b,c,d');
$this->assertSame(5, $f(1, 2, 3, 4));
$this->assertSame(5, $f(1, 2, 3, 4, 5));

$f2 = U::createLambda('($q, $w, $e, $r) ==> { return $w+$e; }', 'a,b,c,d');
$this->assertSame($f, $f2);
$this->assertSame(5, $f2(1, 2, 3, 4));
$this->assertSame(5, $f2(1, 2, 3, 4, 5));
}

/** @covers YaLinqo\Utils::createComparer
Expand Down Expand Up @@ -226,5 +233,7 @@ function testLambdaToSortFlagsAndOrder_sortOrder ()
$order = SORT_DESC;
U::lambdaToSortFlagsAndOrder(null, $order);
$this->assertSame(SORT_DESC, $order);

$this->assertSame(1, U::lambdaToSortFlagsAndOrder(1, $order));
}
}
10 changes: 1 addition & 9 deletions YaLinqo/EnumerableGeneration.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,16 @@ public static function from ($source)
return $source;
else if (is_array($source))
$it = new \ArrayIterator($source);
elseif ($source instanceof \Iterator)
$it = $source;
elseif ($source instanceof \IteratorAggregate)
$it = $source->getIterator();
elseif ($source instanceof \Traversable)
$it = self::fromTraversable($source);
$it = $source;
if ($it !== null) {
return new self($it, false);
}
throw new \InvalidArgumentException('source must be array or Traversable.');
}

private static function fromTraversable ($source)
{
foreach ($source as $k => $v)
yield $k => $v;
}

/**
* Generates a sequence by mimicking a for loop.
* <p><b>Syntax</b>: generate (funcValue {(v, k) ==> value} [, seedValue [, funcKey {(v, k) ==> key} [, seedKey]]])
Expand Down
2 changes: 0 additions & 2 deletions YaLinqo/EnumerablePagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,6 @@ public function take ($count)
return new self(new \EmptyIterator, false);

return new self(function () use ($count) {
if ($count <= 0)
return;
foreach ($this as $k => $v) {
yield $k => $v;
if (--$count == 0)
Expand Down
9 changes: 7 additions & 2 deletions YaLinqo/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class Utils
'strnatcasecmp' => 14 /*SORT_NATURAL | SORT_FLAG_CASE*/,
];

/** @internal */
/**
* @codeCoverageIgnore
* @internal
*/
public static function init ()
{
self::$lambdaCache = [
Expand Down Expand Up @@ -150,9 +153,11 @@ private static function createLambdaFromString ($closure, $closureArgs)
$code = trim($code, " \r\n\t");
if (strlen($code) > 0 && $code[0] != '{')
$code = "return {$code};";
$fun = create_function($args, $code);
$fun = @create_function($args, $code);
// @codeCoverageIgnoreStart
if (!$fun)
throw new \InvalidArgumentException(self::ERROR_CANNOT_PARSE_LAMBDA);
// @codeCoverageIgnoreEnd
self::$lambdaCache[$closure][$closureArgs] = $fun;
return $fun;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php": ">=5.5"
},
"require-dev": {
"phpunit/phpunit": "^4.6",
"phpunit/phpunit": "<6",
"phpdocumentor/phpdocumentor": "^2.8",
"satooshi/php-coveralls": "^2.0"
},
Expand Down
10 changes: 0 additions & 10 deletions phpunit.xml

This file was deleted.

20 changes: 20 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<phpunit bootstrap="vendor/autoload.php"
colors="true">

<testsuites>
<testsuite>
<directory>Tests/Unit/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">YaLinqo/</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-text" target="php://stdout"/>
</logging>
</phpunit>

0 comments on commit 0cfe1bc

Please sign in to comment.