Skip to content

Commit

Permalink
Add is_countable under PHP 7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
carusogabriel authored and nicolas-grekas committed Apr 25, 2018
1 parent 86e2777 commit 803a622
Show file tree
Hide file tree
Showing 24 changed files with 166 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ matrix:
- php: 5.6
- php: 7.0
- php: 7.1
- php: 7.2
- php: nightly
fast_finish: true

before_install:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Polyfills are provided for:
`mbstring.func_overload` is required;
- the `spl_object_id` and `stream_isatty` functions introduced in PHP 7.2;
- the `sapi_windows_vt100_support` function (Windows only) introduced in PHP 7.2;
- the `PHP_OS_FAMILY` constant introduced in PHP 7.2.
- the `PHP_OS_FAMILY` constant introduced in PHP 7.2;
- the `is_countable` function introduced in PHP 7.3.

It is strongly recommended to upgrade your PHP version and/or install the missing
extensions whenever possible. This polyfill should be used only when there is no
Expand All @@ -58,6 +59,7 @@ should **not** `require` the `symfony/polyfill` package, but the standalone ones
- `symfony/polyfill-php70` for using the PHP 7.0 functions,
- `symfony/polyfill-php71` for using the PHP 7.1 functions,
- `symfony/polyfill-php72` for using the PHP 7.2 functions,
- `symfony/polyfill-php73` for using the PHP 7.3 functions,
- `symfony/polyfill-iconv` for using the iconv functions,
- `symfony/polyfill-intl-grapheme` for using the `grapheme_*` functions,
- `symfony/polyfill-intl-icu` for using the intl functions and classes,
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"symfony/polyfill-php70": "self.version",
"symfony/polyfill-php71": "self.version",
"symfony/polyfill-php72": "self.version",
"symfony/polyfill-php73": "self.version",
"symfony/polyfill-iconv": "self.version",
"symfony/polyfill-intl-grapheme": "self.version",
"symfony/polyfill-intl-icu": "self.version",
Expand All @@ -50,6 +51,7 @@
"src/Php70/bootstrap.php",
"src/Php71/bootstrap.php",
"src/Php72/bootstrap.php",
"src/Php73/bootstrap.php",
"src/Iconv/bootstrap.php",
"src/Intl/Grapheme/bootstrap.php",
"src/Intl/Icu/bootstrap.php",
Expand All @@ -65,7 +67,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.8-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Apcu/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.8-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Iconv/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.8-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Intl/Grapheme/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.8-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Intl/Icu/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.8-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Intl/Normalizer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.8-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Mbstring/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.8-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Php54/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.8-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Php55/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.8-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Php56/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.8-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Php70/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.8-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Php71/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.8-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Php72/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.8-dev"
}
}
}
19 changes: 19 additions & 0 deletions src/Php73/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2018 Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
14 changes: 14 additions & 0 deletions src/Php73/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Symfony Polyfill / Php73
========================

This component provides functions added to PHP 7.3 core:

- [`is_countable`](https://php.net/is_countable)

More information can be found in the
[main Polyfill README](https://github.com/symfony/polyfill/blob/master/README.md).

License
=======

This library is released under the [MIT license](LICENSE).
18 changes: 18 additions & 0 deletions src/Php73/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

if (PHP_VERSION_ID < 70300) {
if (!function_exists('is_countable')) {
function is_countable($var) {
return is_array($var) || $var instanceof Countable;
}
}
}
31 changes: 31 additions & 0 deletions src/Php73/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "symfony/polyfill-php73",
"type": "library",
"description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions",
"keywords": ["polyfill", "shim", "compatibility", "portable"],
"homepage": "https://symfony.com",
"license": "MIT",
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"require": {
"php": ">=5.3.3"
},
"autoload": {
"psr-4": { "Symfony\\Polyfill\\Php73\\": "" },
"files": [ "bootstrap.php" ]
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.8-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Util/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.8-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Xml/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.8-dev"
}
}
}
2 changes: 1 addition & 1 deletion tests/Mbstring/MbstringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function testEncodeNumericEntityWarnsOnInvalidEncodingType()
*/
public function testEncodeNumericEntityWarnsOnInvalidIsHexType()
{
$this->setExpectedException('PHPUnit\Framework\Error\Warning', 'expects parameter 4 to be boolean');
$this->setExpectedException('PHPUnit\Framework\Error\Warning', 'expects parameter 4 to be bool');
mb_encode_numericentity('déjà', array(0x0, 0x10ffff, 0x0, 0x1fffff), 'UTF-8', new \stdClass());
}

Expand Down
42 changes: 42 additions & 0 deletions tests/Php73/Php73Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Polyfill\Tests\Php73;

use PHPUnit\Framework\TestCase;

/**
* @author Gabriel Caruso <carusogabriel34@gmail.com>
*/
class Php73Test extends TestCase
{
/**
* @covers Symfony\Polyfill\Php73\Php73::is_countable
*/
public function testIsCountable()
{
$this->assertTrue(is_countable(array(1, 2, '3')));
$this->assertTrue(is_countable(new \ArrayIterator(array('foo', 'bar', 'baz'))));
$this->assertTrue(is_countable(new \ArrayIterator()));
$this->assertFalse(is_countable(new \stdClass()));
}

/**
* @covers Symfony\Polyfill\Php73\Php73::is_countable
* @requires PHP 5.5
*/
public function testIsCountableForGenerator()
{
require 'generator.php';

$this->assertFalse(is_countable(genOneToTen()));
}
}
19 changes: 19 additions & 0 deletions tests/Php73/generator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Polyfill\Tests\Php73;

function genOneToTen()
{
for ($i = 1; $i <= 10; ++$i) {
yield $i;
}
}

0 comments on commit 803a622

Please sign in to comment.