From cdb2e05cf4f48822920e5fb85c0983a155109885 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Thu, 9 Jan 2020 18:53:08 -0600 Subject: [PATCH 01/12] chore(ci): test against PHP 7.4 * Updated to test again PHP 7.4 and to use that for coverage reporting. * Added PHP nightly builds as an allowable failure. * Added a git ignore as well as a `phpunit` configuration. * Updated the tests and CI configuration to better handle the juggling of PHP and `phpunit` versions. * Updated the coveralls dependency to be the latest and greatest instead of the deprecated package. * Tweaked the README, updated the LICENSE years and bumped this package's version. * Dropped Patreon link in favor of using Github Sponsors. --- .gitignore | 4 +++ .travis.yml | 22 ++++++++-------- FUNDING.yml | 1 + LICENSE | 2 +- README.md | 12 ++++----- composer.json | 55 ++++++++++++++++++++-------------------- phpunit.xml | 23 +++++++++++++++++ src/LoremIpsum.php | 2 +- tests/LoremIpsumTest.php | 55 +++++++++++++++++++++++----------------- 9 files changed, 106 insertions(+), 70 deletions(-) create mode 100644 .gitignore create mode 100644 FUNDING.yml create mode 100644 phpunit.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a2144a3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +composer.lock +composer.phar +.phpunit.result.cache +/vendor/ diff --git a/.travis.yml b/.travis.yml index b7be01f..36d3649 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,27 +14,27 @@ matrix: dist: trusty - php: 7.0 dist: xenial - env: PHPUNIT=5.7 - php: 7.1 - php: 7.2 - php: 7.3 + - php: 7.4 + env: COVERAGE=true + - php: nightly + allow_failures: + - php: nightly install: + - php --version - composer install - - if [[ $PHPUNIT == 5.7 ]]; then composer require "phpunit/phpunit:5.7"; fi before_script: - mkdir -p build/logs - - cd tests script: - - | - if [[ $PHPUNIT == 5.7 ]]; then - ../vendor/bin/phpunit --colors --coverage-clover ../build/logs/clover.xml . - else - phpunit --colors --coverage-clover ../build/logs/clover.xml . - fi + - vendor/bin/phpunit --coverage-clover build/logs/clover.xml after_success: - - cd .. - - php vendor/bin/coveralls --config .coveralls.yml -v + - | + if [[ $COVERAGE ]]; then + travis_retry php vendor/bin/php-coveralls --config .coveralls.yml -v + fi diff --git a/FUNDING.yml b/FUNDING.yml new file mode 100644 index 0000000..8b5faa1 --- /dev/null +++ b/FUNDING.yml @@ -0,0 +1 @@ +patreon: joshtronic diff --git a/LICENSE b/LICENSE index ea461be..80b6dad 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014, 2015, 2016, 2017, 2018, 2019 Josh Sherman +Copyright (c) 2014, 2015, 2016, 2017, 2018, 2019, 2020 Josh Sherman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 7ea594d..fb7d1df 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # php-loremipsum -[![Build Status](https://travis-ci.org/joshtronic/php-loremipsum.svg?branch=master)](https://travis-ci.org/joshtronic/php-loremipsum) -[![Coverage Status](https://coveralls.io/repos/github/joshtronic/php-loremipsum/badge.svg?branch=master)](https://coveralls.io/github/joshtronic/php-loremipsum?branch=master) -[![Total Downloads](https://poser.pugx.org/joshtronic/php-loremipsum/downloads)](https://packagist.org/packages/joshtronic/php-loremipsum) +[![License](https://img.shields.io/packagist/l/joshtronic/php-loremipsum?style=for-the-badge)](https://github.com/joshtronic/php-loremipsum/blob/master/LICENSE) +![PHP Version](https://img.shields.io/packagist/php-v/joshtronic/php-loremipsum?style=for-the-badge) +[![Build Status](https://img.shields.io/travis/joshtronic/php-loremipsum/master?style=for-the-badge)](https://travis-ci.org/joshtronic/php-loremipsum) +[![Coverage Status](https://img.shields.io/coveralls/github/joshtronic/php-loremipsum/master?style=for-the-badge)](https://coveralls.io/github/joshtronic/php-loremipsum?branch=master) +[![Monthly Downloads](https://img.shields.io/packagist/dm/joshtronic/php-loremipsum?style=for-the-badge)](https://packagist.org/packages/joshtronic/php-loremipsum) Lorem ipsum generator in PHP without dependencies. Compatible with PHP 5.3+. -[![Become a Patron](https://joshtronic.com/images/become-patron.png)](https://www.patreon.com/joshtronic) - ## Installation The preferred installation method is via `composer`. First add the following to @@ -105,7 +105,7 @@ Suggestions and bug reports are always welcome, but karma points are earned for pull requests. Unit tests are required for all contributions. You can run the test suite from -the `tests` directory simply by running `phpunit .` +the project's root directory simply by running `phpunit`. ## Credits diff --git a/composer.json b/composer.json index 8681045..52ed17d 100644 --- a/composer.json +++ b/composer.json @@ -1,31 +1,30 @@ { - "name": "joshtronic/php-loremipsum", - "description": "Lorem ipsum generator in PHP without dependencies", - "version": "1.0.4", - "type": "library", - "keywords": [ - "lorem", - "ipsum", - "generator" - ], - "homepage": "https://github.com/joshtronic/php-loremipsum", - "license": "MIT", - "authors": [ - { - "name": "Josh Sherman", - "email": "hello@joshtronic.com", - "homepage": "https://joshtronic.com" - } - ], - "require": { - "php": ">=5.3.0" - }, - "require-dev": { - "satooshi/php-coveralls": "~1.0" - }, - "autoload": { - "psr-4": { - "joshtronic\\": "src/" - } + "name": "joshtronic/php-loremipsum", + "description": "Lorem ipsum generator in PHP without dependencies", + "version": "1.0.5", + "type": "library", + "keywords": [ + "lorem", + "ipsum", + "generator" + ], + "homepage": "https://github.com/joshtronic/php-loremipsum", + "license": "MIT", + "authors": [{ + "name": "Josh Sherman", + "email": "hello@joshtronic.com", + "homepage": "https://joshtronic.com" + }], + "require": { + "php": ">=5.3" + }, + "require-dev": { + "php-coveralls/php-coveralls": ">=1", + "phpunit/phpunit": ">=4" + }, + "autoload": { + "psr-4": { + "joshtronic\\": "src/" } + } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..eea8f91 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,23 @@ + + + + + tests + + + + + ./src + + + diff --git a/src/LoremIpsum.php b/src/LoremIpsum.php index 6994156..6db3cb6 100644 --- a/src/LoremIpsum.php +++ b/src/LoremIpsum.php @@ -9,7 +9,7 @@ * Redistribution of these files must retain the above copyright notice. * * @author Josh Sherman - * @copyright Copyright 2014, 2015, 2016, 2017, 2018, 2019 Josh Sherman + * @copyright Copyright 2014, 2015, 2016, 2017, 2018, 2019, 2020 Josh Sherman * @license http://www.opensource.org/licenses/mit-license.html * @link https://github.com/joshtronic/php-loremipsum */ diff --git a/tests/LoremIpsumTest.php b/tests/LoremIpsumTest.php index e568b4d..e05ffbb 100644 --- a/tests/LoremIpsumTest.php +++ b/tests/LoremIpsumTest.php @@ -1,6 +1,5 @@ lipsum = new joshtronic\LoremIpsum(); - } - public function testWord() { - $this->assertRegExp('/^[a-z]+$/i', $this->lipsum->word()); + $lipsum = new joshtronic\LoremIpsum(); + $this->assertRegExp('/^[a-z]+$/i', $lipsum->word()); } public function testWords() { + $lipsum = new joshtronic\LoremIpsum(); $this->assertRegExp( '/^[a-z]+ [a-z]+ [a-z]+$/i', - $this->lipsum->words(3) + $lipsum->words(3) ); } public function testWordsArray() { - $words = $this->lipsum->wordsArray(3); + $lipsum = new joshtronic\LoremIpsum(); + $words = $lipsum->wordsArray(3); $this->assertTrue(is_array($words)); $this->assertCount(3, $words); @@ -44,22 +39,29 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase public function testWordsExceedingVocab() { - $this->assertCount(500, $this->lipsum->wordsArray(500)); + $lipsum = new joshtronic\LoremIpsum(); + $this->assertCount(500, $lipsum->wordsArray(500)); } public function testSentence() { - $this->assertRegExp('/^[a-z, ]+\.$/i', $this->lipsum->sentence()); + $lipsum = new joshtronic\LoremIpsum(); + $this->assertRegExp('/^[a-z, ]+\.$/i', $lipsum->sentence()); } public function testSentences() { - $this->assertRegExp('/^[a-z, ]+\. [a-z, ]+\. [a-z, ]+\.$/i', $this->lipsum->sentences(3)); + $lipsum = new joshtronic\LoremIpsum(); + $this->assertRegExp( + '/^[a-z, ]+\. [a-z, ]+\. [a-z, ]+\.$/i', + $lipsum->sentences(3) + ); } public function testSentencesArray() { - $sentences = $this->lipsum->sentencesArray(3); + $lipsum = new joshtronic\LoremIpsum(); + $sentences = $lipsum->sentencesArray(3); $this->assertTrue(is_array($sentences)); $this->assertCount(3, $sentences); @@ -70,20 +72,23 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase public function testParagraph() { - $this->assertRegExp('/^([a-z, ]+\.)+$/i', $this->lipsum->paragraph()); + $lipsum = new joshtronic\LoremIpsum(); + $this->assertRegExp('/^([a-z, ]+\.)+$/i', $lipsum->paragraph()); } public function testParagraphs() { + $lipsum = new joshtronic\LoremIpsum(); $this->assertRegExp( '/^([a-z, ]+\.)+\n\n([a-z, ]+\.)+\n\n([a-z, ]+\.)+$/i', - $this->lipsum->paragraphs(3) + $lipsum->paragraphs(3) ); } public function testParagraphsArray() { - $paragraphs = $this->lipsum->paragraphsArray(3); + $lipsum = new joshtronic\LoremIpsum(); + $paragraphs = $lipsum->paragraphsArray(3); $this->assertTrue(is_array($paragraphs)); $this->assertCount(3, $paragraphs); @@ -94,31 +99,35 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase public function testMarkupString() { + $lipsum = new joshtronic\LoremIpsum(); $this->assertRegExp( '/^
  • [a-z]+<\/li>$/i', - $this->lipsum->word('li') + $lipsum->word('li') ); } public function testMarkupArray() { + $lipsum = new joshtronic\LoremIpsum(); $this->assertRegExp( '/^

    [a-z]+<\/p><\/div>$/i', - $this->lipsum->word(array('div', 'p')) + $lipsum->word(array('div', 'p')) ); } public function testMarkupBackReference() { + $lipsum = new joshtronic\LoremIpsum(); $this->assertRegExp( '/^

  • [a-z]+<\/a><\/li>$/i', - $this->lipsum->word('
  • $1
  • ') + $lipsum->word('
  • $1
  • ') ); } public function testMarkupArrayReturn() { - $words = $this->lipsum->wordsArray(3, 'li'); + $lipsum = new joshtronic\LoremIpsum(); + $words = $lipsum->wordsArray(3, 'li'); $this->assertTrue(is_array($words)); $this->assertCount(3, $words); From 73e356956cb1192423727cdc642d79de6f1d58f3 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Mon, 2 Mar 2020 20:53:03 -0600 Subject: [PATCH 02/12] docs: update funding --- FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FUNDING.yml b/FUNDING.yml index 8b5faa1..9396c28 100644 --- a/FUNDING.yml +++ b/FUNDING.yml @@ -1 +1 @@ -patreon: joshtronic +github: joshtronic From f0ec43a045b9bfa5e68cac01805e6312a9e9c7e6 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Mon, 1 Jun 2020 22:14:03 -0500 Subject: [PATCH 03/12] ci: switch to github actions Dropped Travis CI and Coveralls for GitHub Actions and CodeCov. --- .coveralls.yml | 1 - .github/workflows/test.yml | 29 +++++++++++++++++++++++++++ .travis.yml | 40 -------------------------------------- README.md | 4 ++-- codecov.yml | 20 +++++++++++++++++++ composer.json | 3 +-- 6 files changed, 52 insertions(+), 45 deletions(-) delete mode 100644 .coveralls.yml create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml create mode 100644 codecov.yml diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index 9160059..0000000 --- a/.coveralls.yml +++ /dev/null @@ -1 +0,0 @@ -service_name: travis-ci diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..41cef6c --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,29 @@ +name: Test +on: [push, pull_request] +jobs: + test: + name: Test PHP ${{ matrix.php-version }} + runs-on: ubuntu-latest + strategy: + matrix: + php-version: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + - name: PHP Version + run: php --version + - name: Composer Version + run: composer --version + - name: Install Dependencies + run: COMPOSER_MEMORY_LIMIT=-1 composer install + - name: Run Tests + run: vendor/bin/phpunit --coverage-clover ./coverage.xml + - name: Upload Coverage + if: ${{ matrix.php-version == '7.4' }} + uses: codecov/codecov-action@v1 + with: + file: ./coverage.xml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 36d3649..0000000 --- a/.travis.yml +++ /dev/null @@ -1,40 +0,0 @@ -language: php -dist: bionic -sudo: required - -matrix: - include: - - php: 5.3 - dist: precise - - php: 5.4 - dist: trusty - - php: 5.5 - dist: trusty - - php: 5.6 - dist: trusty - - php: 7.0 - dist: xenial - - php: 7.1 - - php: 7.2 - - php: 7.3 - - php: 7.4 - env: COVERAGE=true - - php: nightly - allow_failures: - - php: nightly - -install: - - php --version - - composer install - -before_script: - - mkdir -p build/logs - -script: - - vendor/bin/phpunit --coverage-clover build/logs/clover.xml - -after_success: - - | - if [[ $COVERAGE ]]; then - travis_retry php vendor/bin/php-coveralls --config .coveralls.yml -v - fi diff --git a/README.md b/README.md index fb7d1df..2b29143 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ [![License](https://img.shields.io/packagist/l/joshtronic/php-loremipsum?style=for-the-badge)](https://github.com/joshtronic/php-loremipsum/blob/master/LICENSE) ![PHP Version](https://img.shields.io/packagist/php-v/joshtronic/php-loremipsum?style=for-the-badge) -[![Build Status](https://img.shields.io/travis/joshtronic/php-loremipsum/master?style=for-the-badge)](https://travis-ci.org/joshtronic/php-loremipsum) -[![Coverage Status](https://img.shields.io/coveralls/github/joshtronic/php-loremipsum/master?style=for-the-badge)](https://coveralls.io/github/joshtronic/php-loremipsum?branch=master) +[![Test Status](https://img.shields.io/github/workflow/status/joshtronic/php-loremipsum/Test?style=for-the-badge)](https://github.com/joshtronic/php-loremipsum/actions) +[![Code Coverage](https://img.shields.io/codecov/c/github/joshtronic/php-loremipsum?style=for-the-badge)](https://codecov.io/gh/joshtronic/php-loremipsum) [![Monthly Downloads](https://img.shields.io/packagist/dm/joshtronic/php-loremipsum?style=for-the-badge)](https://packagist.org/packages/joshtronic/php-loremipsum) Lorem ipsum generator in PHP without dependencies. Compatible with PHP 5.3+. diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..657d8f7 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,20 @@ +codecov: + require_ci_to_pass: yes + +coverage: + precision: 2 + round: down + range: "70...100" + +parsers: + gcov: + branch_detection: + conditional: yes + loop: yes + method: no + macro: no + +comment: + layout: "reach,diff,flags,tree" + behavior: default + require_changes: no diff --git a/composer.json b/composer.json index 52ed17d..9300c87 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "joshtronic/php-loremipsum", "description": "Lorem ipsum generator in PHP without dependencies", - "version": "1.0.5", + "version": "1.0.6", "type": "library", "keywords": [ "lorem", @@ -19,7 +19,6 @@ "php": ">=5.3" }, "require-dev": { - "php-coveralls/php-coveralls": ">=1", "phpunit/phpunit": ">=4" }, "autoload": { From 007b7a211eb9411edc81586b2b09bb8aecccc82a Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Thu, 1 Oct 2020 10:30:09 +0500 Subject: [PATCH 04/12] Fix #7 Change visibility of $words The PHPDoc block of `$words` say that the visibility / access of `$words` is private but its `public` in php code. https://github.com/joshtronic/php-loremipsum/blob/master/src/LoremIpsum.php#L37-L40 --- src/LoremIpsum.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoremIpsum.php b/src/LoremIpsum.php index 6db3cb6..ebc9dda 100644 --- a/src/LoremIpsum.php +++ b/src/LoremIpsum.php @@ -37,7 +37,7 @@ class LoremIpsum * @access private * @var array */ - public $words = array( + private $words = array( // Lorem ipsum... 'lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit', From 732be48504ab7de5d959b0a8a5502344d93f7e3b Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Mon, 12 Oct 2020 17:42:21 -0500 Subject: [PATCH 05/12] test: update assertion syntax Tweaked the assertion syntax based on some upcoming changes to PHPUnit. --- tests/LoremIpsumTest.php | 111 +++++++++++++++++++++++++++++---------- 1 file changed, 82 insertions(+), 29 deletions(-) diff --git a/tests/LoremIpsumTest.php b/tests/LoremIpsumTest.php index e05ffbb..02bd2f8 100644 --- a/tests/LoremIpsumTest.php +++ b/tests/LoremIpsumTest.php @@ -10,22 +10,42 @@ if ( class LoremIpsumTest extends PHPUnit_Framework_TestCase { - public function testWord() - { - $lipsum = new joshtronic\LoremIpsum(); - $this->assertRegExp('/^[a-z]+$/i', $lipsum->word()); + /** + * @doesNotPerformAssertions + */ + public function testAssertRegExp() { + if (version_compare(PHP_VERSION, '7.3.0', '>=')) { + return 'assertMatchesRegularExpression'; + } + + return 'assertRegExp'; } - public function testWords() + /** + * @depends testAssertRegExp + */ + public function testWord($assertRegExp) { $lipsum = new joshtronic\LoremIpsum(); - $this->assertRegExp( + $this->$assertRegExp('/^[a-z]+$/i', $lipsum->word()); + } + + /** + * @depends testAssertRegExp + */ + public function testWords($assertRegExp) + { + $lipsum = new joshtronic\LoremIpsum(); + $this->$assertRegExp( '/^[a-z]+ [a-z]+ [a-z]+$/i', $lipsum->words(3) ); } - public function testWordsArray() + /** + * @depends testAssertRegExp + */ + public function testWordsArray($assertRegExp) { $lipsum = new joshtronic\LoremIpsum(); $words = $lipsum->wordsArray(3); @@ -33,32 +53,44 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase $this->assertCount(3, $words); foreach ($words as $word) { - $this->assertRegExp('/^[a-z]+$/i', $word); + $this->$assertRegExp('/^[a-z]+$/i', $word); } } - public function testWordsExceedingVocab() + /** + * @depends testAssertRegExp + */ + public function testWordsExceedingVocab($assertRegExp) { $lipsum = new joshtronic\LoremIpsum(); $this->assertCount(500, $lipsum->wordsArray(500)); } - public function testSentence() + /** + * @depends testAssertRegExp + */ + public function testSentence($assertRegExp) { $lipsum = new joshtronic\LoremIpsum(); - $this->assertRegExp('/^[a-z, ]+\.$/i', $lipsum->sentence()); + $this->$assertRegExp('/^[a-z, ]+\.$/i', $lipsum->sentence()); } - public function testSentences() + /** + * @depends testAssertRegExp + */ + public function testSentences($assertRegExp) { $lipsum = new joshtronic\LoremIpsum(); - $this->assertRegExp( + $this->$assertRegExp( '/^[a-z, ]+\. [a-z, ]+\. [a-z, ]+\.$/i', $lipsum->sentences(3) ); } - public function testSentencesArray() + /** + * @depends testAssertRegExp + */ + public function testSentencesArray($assertRegExp) { $lipsum = new joshtronic\LoremIpsum(); $sentences = $lipsum->sentencesArray(3); @@ -66,26 +98,35 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase $this->assertCount(3, $sentences); foreach ($sentences as $sentence) { - $this->assertRegExp('/^[a-z, ]+\.$/i', $sentence); + $this->$assertRegExp('/^[a-z, ]+\.$/i', $sentence); } } - public function testParagraph() + /** + * @depends testAssertRegExp + */ + public function testParagraph($assertRegExp) { $lipsum = new joshtronic\LoremIpsum(); - $this->assertRegExp('/^([a-z, ]+\.)+$/i', $lipsum->paragraph()); + $this->$assertRegExp('/^([a-z, ]+\.)+$/i', $lipsum->paragraph()); } - public function testParagraphs() + /** + * @depends testAssertRegExp + */ + public function testParagraphs($assertRegExp) { $lipsum = new joshtronic\LoremIpsum(); - $this->assertRegExp( + $this->$assertRegExp( '/^([a-z, ]+\.)+\n\n([a-z, ]+\.)+\n\n([a-z, ]+\.)+$/i', $lipsum->paragraphs(3) ); } - public function testParagraphsArray() + /** + * @depends testAssertRegExp + */ + public function testParagraphsArray($assertRegExp) { $lipsum = new joshtronic\LoremIpsum(); $paragraphs = $lipsum->paragraphsArray(3); @@ -93,38 +134,50 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase $this->assertCount(3, $paragraphs); foreach ($paragraphs as $paragraph) { - $this->assertRegExp('/^([a-z, ]+\.)+$/i', $paragraph); + $this->$assertRegExp('/^([a-z, ]+\.)+$/i', $paragraph); } } - public function testMarkupString() + /** + * @depends testAssertRegExp + */ + public function testMarkupString($assertRegExp) { $lipsum = new joshtronic\LoremIpsum(); - $this->assertRegExp( + $this->$assertRegExp( '/^
  • [a-z]+<\/li>$/i', $lipsum->word('li') ); } - public function testMarkupArray() + /** + * @depends testAssertRegExp + */ + public function testMarkupArray($assertRegExp) { $lipsum = new joshtronic\LoremIpsum(); - $this->assertRegExp( + $this->$assertRegExp( '/^

    [a-z]+<\/p><\/div>$/i', $lipsum->word(array('div', 'p')) ); } - public function testMarkupBackReference() + /** + * @depends testAssertRegExp + */ + public function testMarkupBackReference($assertRegExp) { $lipsum = new joshtronic\LoremIpsum(); - $this->assertRegExp( + $this->$assertRegExp( '/^

  • [a-z]+<\/a><\/li>$/i', $lipsum->word('
  • $1
  • ') ); } - public function testMarkupArrayReturn() + /** + * @depends testAssertRegExp + */ + public function testMarkupArrayReturn($assertRegExp) { $lipsum = new joshtronic\LoremIpsum(); $words = $lipsum->wordsArray(3, 'li'); @@ -132,7 +185,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase $this->assertCount(3, $words); foreach ($words as $word) { - $this->assertRegExp('/^
  • [a-z]+<\/li>$/i', $word); + $this->$assertRegExp('/^
  • [a-z]+<\/li>$/i', $word); } } } From ae53465dad7552ccf6667836c7d449dba2f96fe5 Mon Sep 17 00:00:00 2001 From: peter279k Date: Fri, 25 Dec 2020 21:59:22 +0800 Subject: [PATCH 06/12] Improvements about namespace and PHPUnit version --- .github/workflows/test.yml | 2 +- composer.json | 7 ++++++- phpunit.xml | 1 + tests/LoremIpsumTest.php | 41 +++++++++++++++++--------------------- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 41cef6c..ddf8b8d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] + php-version: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] steps: - name: Checkout uses: actions/checkout@v2 diff --git a/composer.json b/composer.json index 9300c87..ebaf162 100644 --- a/composer.json +++ b/composer.json @@ -19,11 +19,16 @@ "php": ">=5.3" }, "require-dev": { - "phpunit/phpunit": ">=4" + "phpunit/phpunit": "^4.8.36 || ^9.0" }, "autoload": { "psr-4": { "joshtronic\\": "src/" } + }, + "autoload-dev": { + "psr-4": { + "joshtronic\\Tests\\": "tests/" + } } } diff --git a/phpunit.xml b/phpunit.xml index eea8f91..8fe6c98 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,6 @@ $assertRegExp('/^[a-z]+$/i', $lipsum->word()); } @@ -35,7 +30,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase */ public function testWords($assertRegExp) { - $lipsum = new joshtronic\LoremIpsum(); + $lipsum = new LoremIpsum(); $this->$assertRegExp( '/^[a-z]+ [a-z]+ [a-z]+$/i', $lipsum->words(3) @@ -47,7 +42,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase */ public function testWordsArray($assertRegExp) { - $lipsum = new joshtronic\LoremIpsum(); + $lipsum = new LoremIpsum(); $words = $lipsum->wordsArray(3); $this->assertTrue(is_array($words)); $this->assertCount(3, $words); @@ -62,7 +57,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase */ public function testWordsExceedingVocab($assertRegExp) { - $lipsum = new joshtronic\LoremIpsum(); + $lipsum = new LoremIpsum(); $this->assertCount(500, $lipsum->wordsArray(500)); } @@ -71,7 +66,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase */ public function testSentence($assertRegExp) { - $lipsum = new joshtronic\LoremIpsum(); + $lipsum = new LoremIpsum(); $this->$assertRegExp('/^[a-z, ]+\.$/i', $lipsum->sentence()); } @@ -80,7 +75,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase */ public function testSentences($assertRegExp) { - $lipsum = new joshtronic\LoremIpsum(); + $lipsum = new LoremIpsum(); $this->$assertRegExp( '/^[a-z, ]+\. [a-z, ]+\. [a-z, ]+\.$/i', $lipsum->sentences(3) @@ -92,7 +87,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase */ public function testSentencesArray($assertRegExp) { - $lipsum = new joshtronic\LoremIpsum(); + $lipsum = new LoremIpsum(); $sentences = $lipsum->sentencesArray(3); $this->assertTrue(is_array($sentences)); $this->assertCount(3, $sentences); @@ -107,7 +102,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase */ public function testParagraph($assertRegExp) { - $lipsum = new joshtronic\LoremIpsum(); + $lipsum = new LoremIpsum(); $this->$assertRegExp('/^([a-z, ]+\.)+$/i', $lipsum->paragraph()); } @@ -116,7 +111,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase */ public function testParagraphs($assertRegExp) { - $lipsum = new joshtronic\LoremIpsum(); + $lipsum = new LoremIpsum(); $this->$assertRegExp( '/^([a-z, ]+\.)+\n\n([a-z, ]+\.)+\n\n([a-z, ]+\.)+$/i', $lipsum->paragraphs(3) @@ -128,7 +123,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase */ public function testParagraphsArray($assertRegExp) { - $lipsum = new joshtronic\LoremIpsum(); + $lipsum = new LoremIpsum(); $paragraphs = $lipsum->paragraphsArray(3); $this->assertTrue(is_array($paragraphs)); $this->assertCount(3, $paragraphs); @@ -143,7 +138,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase */ public function testMarkupString($assertRegExp) { - $lipsum = new joshtronic\LoremIpsum(); + $lipsum = new LoremIpsum(); $this->$assertRegExp( '/^
  • [a-z]+<\/li>$/i', $lipsum->word('li') @@ -155,7 +150,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase */ public function testMarkupArray($assertRegExp) { - $lipsum = new joshtronic\LoremIpsum(); + $lipsum = new LoremIpsum(); $this->$assertRegExp( '/^

    [a-z]+<\/p><\/div>$/i', $lipsum->word(array('div', 'p')) @@ -167,7 +162,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase */ public function testMarkupBackReference($assertRegExp) { - $lipsum = new joshtronic\LoremIpsum(); + $lipsum = new LoremIpsum(); $this->$assertRegExp( '/^

  • [a-z]+<\/a><\/li>$/i', $lipsum->word('
  • $1
  • ') @@ -179,7 +174,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase */ public function testMarkupArrayReturn($assertRegExp) { - $lipsum = new joshtronic\LoremIpsum(); + $lipsum = new LoremIpsum(); $words = $lipsum->wordsArray(3, 'li'); $this->assertTrue(is_array($words)); $this->assertCount(3, $words); From c9e2957c238710c3c3e48972cc5200bbccbec357 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Tue, 4 Jan 2022 21:06:55 -0600 Subject: [PATCH 07/12] feat: ensure passed tags are strings Newer versions of PHP raise a warning if you attempt to use array syntax against non-strings / non-arrays. Added sanity check to ensure we're working with a string, otherwise skip it. Also added in PHP 8.1 to the testing suite and bumped the copyright. Bumped version to 2.0 since as the change in expected output is a breaking change. --- .github/workflows/test.yml | 4 ++-- LICENSE | 2 +- composer.json | 2 +- src/LoremIpsum.php | 14 ++++++++------ tests/LoremIpsumTest.php | 11 +++++++++++ 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ddf8b8d..c492e7a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] + php-version: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] steps: - name: Checkout uses: actions/checkout@v2 @@ -23,7 +23,7 @@ jobs: - name: Run Tests run: vendor/bin/phpunit --coverage-clover ./coverage.xml - name: Upload Coverage - if: ${{ matrix.php-version == '7.4' }} + if: ${{ matrix.php-version == '8.1' }} uses: codecov/codecov-action@v1 with: file: ./coverage.xml diff --git a/LICENSE b/LICENSE index 80b6dad..cc7838a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014, 2015, 2016, 2017, 2018, 2019, 2020 Josh Sherman +Copyright (c) 2014-2022 Josh Sherman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index ebaf162..da7781c 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "joshtronic/php-loremipsum", "description": "Lorem ipsum generator in PHP without dependencies", - "version": "1.0.6", + "version": "2.0.0", "type": "library", "keywords": [ "lorem", diff --git a/src/LoremIpsum.php b/src/LoremIpsum.php index ebc9dda..a48304b 100644 --- a/src/LoremIpsum.php +++ b/src/LoremIpsum.php @@ -9,7 +9,7 @@ * Redistribution of these files must retain the above copyright notice. * * @author Josh Sherman - * @copyright Copyright 2014, 2015, 2016, 2017, 2018, 2019, 2020 Josh Sherman + * @copyright Copyright 2014-2022 Josh Sherman * @license http://www.opensource.org/licenses/mit-license.html * @link https://github.com/joshtronic/php-loremipsum */ @@ -351,11 +351,13 @@ class LoremIpsum foreach ($strings as $key => $string) { foreach ($tags as $tag) { - // Detects / applies back reference - if ($tag[0] == '<') { - $string = str_replace('$1', $string, $tag); - } else { - $string = sprintf('<%1$s>%2$s', $tag, $string); + if (is_string($tag)) { + // Detects / applies back reference + if ($tag[0] == '<') { + $string = str_replace('$1', $string, $tag); + } else { + $string = sprintf('<%1$s>%2$s', $tag, $string); + } } $strings[$key] = $string; diff --git a/tests/LoremIpsumTest.php b/tests/LoremIpsumTest.php index 01d1fec..77c5906 100644 --- a/tests/LoremIpsumTest.php +++ b/tests/LoremIpsumTest.php @@ -183,5 +183,16 @@ class LoremIpsumTest extends TestCase $this->$assertRegExp('/^
  • [a-z]+<\/li>$/i', $word); } } + + /** + * @depends testAssertRegExp + */ + public function testSkipNonStringTag($assertRegExp) + { + $lipsum = new LoremIpsum(); + $this->$assertRegExp('/^[a-z]+$/i', $lipsum->word(123)); + $this->$assertRegExp('/^[a-z]+$/i', $lipsum->word(array(1, 2, 3))); + $this->$assertRegExp('/^[a-z]+$/i', $lipsum->word(true)); + } } From 63a52c853bff27d00e23d9506e25b6f1c3b21007 Mon Sep 17 00:00:00 2001 From: Roy Verrips Date: Wed, 5 Jan 2022 23:21:49 -0600 Subject: [PATCH 08/12] PHP 8.1: Implicit incompatible float to int conversion is deprecated In PHP 8.1 floats are not implicitly converted to integers as before. The array_slice on line 139 requires an integer as the third parameter (the $count variable) so added line 117 to do the conversion of $count. --- src/LoremIpsum.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/LoremIpsum.php b/src/LoremIpsum.php index a48304b..487610b 100644 --- a/src/LoremIpsum.php +++ b/src/LoremIpsum.php @@ -114,6 +114,7 @@ class LoremIpsum */ public function words($count = 1, $tags = false, $array = false) { + $count = (int) $count; $words = array(); $word_count = 0; From 6e973db52189f16c76d6ee9702fac526daadae5f Mon Sep 17 00:00:00 2001 From: Roy Verrips Date: Fri, 7 Jan 2022 11:52:46 -0600 Subject: [PATCH 09/12] Add phpstan with config set to max --- composer.json | 3 ++- phpstan.neon | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index da7781c..0ff53d6 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ "php": ">=5.3" }, "require-dev": { - "phpunit/phpunit": "^4.8.36 || ^9.0" + "phpunit/phpunit": "^4.8.36 || ^9.0", + "phpstan/phpstan": "^1.3" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..0292a3b --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,14 @@ +parameters: + + paths: + - src + + # The level 8 is the highest level + level: max + + excludePaths: + - ./*/*/FileToBeExcluded.php + + checkMissingIterableValueType: true + + #editorUrl: 'vscode://file/%%file%%:%%line%%' From 7cebbfc06ae116993314f801bd10365321fa0596 Mon Sep 17 00:00:00 2001 From: Roy Verrips Date: Fri, 7 Jan 2022 15:00:48 -0600 Subject: [PATCH 10/12] Refactors to satisfy phpstan level 8 --- src/LoremIpsum.php | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/LoremIpsum.php b/src/LoremIpsum.php index 487610b..5085b4f 100644 --- a/src/LoremIpsum.php +++ b/src/LoremIpsum.php @@ -24,7 +24,7 @@ class LoremIpsum * Whether or not we should be starting the string with "Lorem ipsum..." * * @access private - * @var boolean + * @var mixed */ private $first = true; @@ -35,7 +35,7 @@ class LoremIpsum * a complete list exists and if so, where to get it. * * @access private - * @var array + * @var array */ private $words = array( // Lorem ipsum... @@ -83,7 +83,7 @@ class LoremIpsum */ public function word($tags = false) { - return $this->words(1, $tags); + return strval($this->words(1, $tags)); } /** @@ -94,7 +94,7 @@ class LoremIpsum * @access public * @param integer $count how many words to generate * @param mixed $tags string or array of HTML tags to wrap output with - * @return array generated lorem ipsum words + * @return mixed generated lorem ipsum words */ public function wordsArray($count = 1, $tags = false) { @@ -152,7 +152,7 @@ class LoremIpsum */ public function sentence($tags = false) { - return $this->sentences(1, $tags); + return strval($this->sentences(1, $tags)); } /** @@ -163,7 +163,7 @@ class LoremIpsum * @access public * @param integer $count how many sentences to generate * @param mixed $tags string or array of HTML tags to wrap output with - * @return array generated lorem ipsum sentences + * @return mixed generated lorem ipsum sentences */ public function sentencesArray($count = 1, $tags = false) { @@ -205,7 +205,7 @@ class LoremIpsum */ public function paragraph($tags = false) { - return $this->paragraphs(1, $tags); + return strval($this->paragraphs(1, $tags)); } /** @@ -216,15 +216,18 @@ class LoremIpsum * @access public * @param integer $count how many paragraphs to generate * @param mixed $tags string or array of HTML tags to wrap output with - * @return array generated lorem ipsum paragraphs + * @return array generated lorem ipsum paragraphs */ public function paragraphsArray($count = 1, $tags = false) { + // The $array parameter set to true means an array is returned. + // Return type is mixed, we should probably cast to array. + // @phpstan-ignore-next-line return $this->paragraphs($count, $tags, true); } /** - * Paragraphss + * Paragraphs * * Generates paragraphs of lorem ipsum. * @@ -239,10 +242,13 @@ class LoremIpsum $paragraphs = array(); for ($i = 0; $i < $count; $i++) { - $paragraphs[] = $this->sentences($this->gauss(5.8, 1.93)); + $paragraphs[] = strval($this->sentences($this->gauss(5.8, 1.93))); } - return $this->output($paragraphs, $tags, $array, "\n\n"); + if ($array) { + return $this->output($paragraphs, $tags, $array, "\n\n"); + } + return strval($this->output($paragraphs, $tags, false, "\n\n")); } /** @@ -256,7 +262,7 @@ class LoremIpsum * @access private * @param double $mean average value * @param double $std_dev stadnard deviation - * @return double calculated distribution + * @return int calculated distribution */ private function gauss($mean, $std_dev) { @@ -264,7 +270,7 @@ class LoremIpsum $y = mt_rand() / mt_getrandmax(); $z = sqrt(-2 * log($x)) * cos(2 * pi() * $y); - return $z * $std_dev + $mean; + return intval($z * $std_dev + $mean); } /** @@ -274,6 +280,7 @@ class LoremIpsum * the first time we are generating the text. * * @access private + * @return void */ private function shuffle() { @@ -299,18 +306,19 @@ class LoremIpsum * first word of the sentence. * * @access private - * @param array $sentences the sentences we would like to punctuate + * @param array $sentences the sentences we would like to punctuate + * @return void */ private function punctuate(&$sentences) { foreach ($sentences as $key => $sentence) { - $words = count($sentence); + $words = count($sentences); // Only worry about commas on sentences longer than 4 words if ($words > 4) { $mean = log($words, 6); $std_dev = $mean / 6; - $commas = round($this->gauss($mean, $std_dev)); + $commas = $this->gauss($mean, $std_dev); for ($i = 1; $i <= $commas; $i++) { $word = round($i * $words / ($commas + 1)); @@ -334,7 +342,7 @@ class LoremIpsum * into a string or not. * * @access private - * @param array $strings an array of generated strings + * @param array $strings an array of generated strings * @param mixed $tags string or array of HTML tags to wrap output with * @param boolean $array whether an array or a string should be returned * @param string $delimiter the string to use when calling implode() @@ -373,4 +381,3 @@ class LoremIpsum return $strings; } } - From a84cdd8917e90f096ed1978d4b760ca77d803aaf Mon Sep 17 00:00:00 2001 From: Roy Verrips Date: Fri, 7 Jan 2022 18:19:11 -0600 Subject: [PATCH 11/12] Remove phpstan from dependancies - want to keep this compatible with php 7.0 as per github build steps --- composer.json | 63 +++++++++++++++++++++++----------------------- src/LoremIpsum.php | 3 +-- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/composer.json b/composer.json index 0ff53d6..8141871 100644 --- a/composer.json +++ b/composer.json @@ -1,35 +1,34 @@ { - "name": "joshtronic/php-loremipsum", - "description": "Lorem ipsum generator in PHP without dependencies", - "version": "2.0.0", - "type": "library", - "keywords": [ - "lorem", - "ipsum", - "generator" - ], - "homepage": "https://github.com/joshtronic/php-loremipsum", - "license": "MIT", - "authors": [{ - "name": "Josh Sherman", - "email": "hello@joshtronic.com", - "homepage": "https://joshtronic.com" - }], - "require": { - "php": ">=5.3" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.36 || ^9.0", - "phpstan/phpstan": "^1.3" - }, - "autoload": { - "psr-4": { - "joshtronic\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "joshtronic\\Tests\\": "tests/" + "name": "joshtronic/php-loremipsum", + "description": "Lorem ipsum generator in PHP without dependencies", + "version": "2.0.0", + "type": "library", + "keywords": [ + "lorem", + "ipsum", + "generator" + ], + "homepage": "https://github.com/joshtronic/php-loremipsum", + "license": "MIT", + "authors": [{ + "name": "Josh Sherman", + "email": "hello@joshtronic.com", + "homepage": "https://joshtronic.com" + }], + "require": { + "php": ">=5.3" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.36 || ^9.0" + }, + "autoload": { + "psr-4": { + "joshtronic\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "joshtronic\\Tests\\": "tests/" + } } } -} diff --git a/src/LoremIpsum.php b/src/LoremIpsum.php index 5085b4f..863b8d5 100644 --- a/src/LoremIpsum.php +++ b/src/LoremIpsum.php @@ -312,8 +312,7 @@ class LoremIpsum private function punctuate(&$sentences) { foreach ($sentences as $key => $sentence) { - $words = count($sentences); - + $words = count($sentence); // Only worry about commas on sentences longer than 4 words if ($words > 4) { $mean = log($words, 6); From 6d7f8cff6a092a53d66b5237edbe97d398b14f88 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Sun, 23 Jan 2022 17:27:44 -0600 Subject: [PATCH 12/12] chore: bump version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8141871..a28a4b3 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "joshtronic/php-loremipsum", "description": "Lorem ipsum generator in PHP without dependencies", - "version": "2.0.0", + "version": "2.1.0", "type": "library", "keywords": [ "lorem",