Compare commits
52 commits
Author | SHA1 | Date | |
---|---|---|---|
6d7f8cff6a | |||
|
a84cdd8917 | ||
|
7cebbfc06a | ||
|
6e973db521 | ||
|
63a52c853b | ||
c9e2957c23 | |||
|
ae53465dad | ||
732be48504 | |||
|
007b7a211e | ||
f0ec43a045 | |||
73e356956c | |||
cdb2e05cf4 | |||
e41f4f7630 | |||
24b768a630 | |||
e6668afb5a | |||
5fa8d5b300 | |||
a82b10394d | |||
fc7ce83cbc | |||
dd120b7832 | |||
551a2d790d | |||
1f016c6b4b | |||
3d4ceeb6fd | |||
c6b8669c2c | |||
9cbee4918f | |||
ffbdd892a3 | |||
a7bf9d29c0 | |||
1943a9b79f | |||
5ed7322647 | |||
30f193b036 | |||
8d0bd22b1b | |||
333323c9b3 | |||
e033baaa79 | |||
62835bea13 | |||
1bd9b03dda | |||
c4f6f06000 | |||
a6a4017906 | |||
5352b2d7ff | |||
010f86775a | |||
2e3b28d12d | |||
3454bd7488 | |||
02bae95170 | |||
c270610543 | |||
31f5869ed9 | |||
6e8495f056 | |||
19be9e5dcd | |||
1a73da34f4 | |||
283a730230 | |||
57f38f3193 | |||
|
5ad1e4e9f7 | ||
|
cf41dcfdad | ||
|
6a03636f11 | ||
|
ece0a6f057 |
13 changed files with 358 additions and 259 deletions
|
@ -1 +0,0 @@
|
||||||
service_name: travis-ci
|
|
29
.github/workflows/test.yml
vendored
Normal file
29
.github/workflows/test.yml
vendored
Normal file
|
@ -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', '8.0', '8.1']
|
||||||
|
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 == '8.1' }}
|
||||||
|
uses: codecov/codecov-action@v1
|
||||||
|
with:
|
||||||
|
file: ./coverage.xml
|
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
composer.lock
|
||||||
|
composer.phar
|
||||||
|
.phpunit.result.cache
|
||||||
|
/vendor/
|
26
.travis.yml
26
.travis.yml
|
@ -1,26 +0,0 @@
|
||||||
language: php
|
|
||||||
|
|
||||||
php:
|
|
||||||
- 5.3
|
|
||||||
- 5.4
|
|
||||||
- 5.5
|
|
||||||
- 5.6
|
|
||||||
- hhvm
|
|
||||||
|
|
||||||
matrix:
|
|
||||||
allow_failures:
|
|
||||||
- php: 5.6
|
|
||||||
- php: hhvm
|
|
||||||
|
|
||||||
install:
|
|
||||||
- composer install
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- mkdir -p build/logs
|
|
||||||
- cd tests
|
|
||||||
|
|
||||||
script:
|
|
||||||
- phpunit --colors --coverage-clover /home/travis/build/joshtronic/php-loremipsum/build/logs/clover.xml .
|
|
||||||
|
|
||||||
after_success:
|
|
||||||
- php ../vendor/bin/coveralls --config ../.coveralls.yml -v
|
|
1
FUNDING.yml
Normal file
1
FUNDING.yml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
github: joshtronic
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014 Josh Sherman
|
Copyright (c) 2014-2022 Josh Sherman
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
87
README.md
87
README.md
|
@ -1,53 +1,25 @@
|
||||||
# php-loremipsum
|
# php-loremipsum
|
||||||
|
|
||||||
[][travis]
|
[](https://github.com/joshtronic/php-loremipsum/blob/master/LICENSE)
|
||||||
[][coveralls]
|

|
||||||
[][packagist]
|
[](https://github.com/joshtronic/php-loremipsum/actions)
|
||||||
[][gittip]
|
[](https://codecov.io/gh/joshtronic/php-loremipsum)
|
||||||
|
[](https://packagist.org/packages/joshtronic/php-loremipsum)
|
||||||
|
|
||||||
[travis]: http://travis-ci.org/joshtronic/php-loremipsum
|
Lorem ipsum generator in PHP without dependencies. Compatible with PHP 5.3+.
|
||||||
[coveralls]: https://coveralls.io/r/joshtronic/php-loremipsum
|
|
||||||
[packagist]: https://packagist.org/packages/joshtronic/php-loremipsum
|
|
||||||
[gittip]: https://www.gittip.com/joshtronic/
|
|
||||||
|
|
||||||
Lorem ipsum generator in PHP without dependencies. Compatible with PHP 5.3+ as
|
|
||||||
well as HHVM.
|
|
||||||
|
|
||||||
## Origins
|
|
||||||
|
|
||||||
Once upon a time, I was attempting to find a lorem ipsum generator over on
|
|
||||||
[Packagist](https://packagist.org/search/?q=lorem%20ipsum). I was presented
|
|
||||||
with many options, and some of those options were good. Unfortunately, the
|
|
||||||
bulk of those options depended on Symphony or the Zend Framework. This
|
|
||||||
wouldn’t have been a big deal but under the circumstances, I wanted something
|
|
||||||
that was not tightly coupled to these frameworks because I wanted to use the
|
|
||||||
generator in my _own_ framework.
|
|
||||||
|
|
||||||
I had decided to use
|
|
||||||
[badcow/lorem-ipsum](https://packagist.org/packages/badcow/lorem-ipsum)
|
|
||||||
because it did not have any dependencies nor did it rely on any external APIs.
|
|
||||||
As I started to use the library, I found that I was going to have to fight
|
|
||||||
with it to get it to do what I wanted. After digging through the code, I
|
|
||||||
realized that I was going to end up gutting most of it to bend it to my will.
|
|
||||||
I know when you overhaul someone’s code the liklihood of them accepting a pull
|
|
||||||
request goes down dramatically, hence building this library while taking cues
|
|
||||||
from it’s predecessor.
|
|
||||||
|
|
||||||
Also, the aforementioned package had a bunch of “setter” and “getter” methods
|
|
||||||
that were grossing me out :scream:
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
The preferred installation method is via `composer`. First add the following
|
The preferred installation method is via `composer`. First add the following to
|
||||||
to your `composer.json`
|
your `composer.json`:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"require": {
|
"require": {
|
||||||
"joshtronic/php-loremipsum": "1.0.*"
|
"joshtronic/php-loremipsum": "dev-master"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Then run `composer update`
|
Then run `composer update`.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
@ -64,21 +36,21 @@ echo '1 word: ' . $lipsum->word();
|
||||||
echo '5 words: ' . $lipsum->words(5);
|
echo '5 words: ' . $lipsum->words(5);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Generating sentences
|
### Generating Sentences
|
||||||
|
|
||||||
```php
|
```php
|
||||||
echo '1 sentence: ' . $lipsum->sentence();
|
echo '1 sentence: ' . $lipsum->sentence();
|
||||||
echo '5 sentences: ' . $lipsum->sentences(5);
|
echo '5 sentences: ' . $lipsum->sentences(5);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Generating paragraphs
|
### Generating Paragraphs
|
||||||
|
|
||||||
```php
|
```php
|
||||||
echo '1 paragraph: ' . $lipsum->paragraph();
|
echo '1 paragraph: ' . $lipsum->paragraph();
|
||||||
echo '5 paragraphs: ' . $lipsum->paragraphs(5);
|
echo '5 paragraphs: ' . $lipsum->paragraphs(5);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Wrapping text with HTML tags
|
### Wrapping Text with HTML Tags
|
||||||
|
|
||||||
If you would like to wrap the generated text with a tag, pass it as the second
|
If you would like to wrap the generated text with a tag, pass it as the second
|
||||||
parameter:
|
parameter:
|
||||||
|
@ -105,7 +77,7 @@ echo $lipsum->words(3, '<li><a href="$1">$1</a></li>');
|
||||||
// Generates: <li><a href="...">...</a></li><li><a href="...">...</a></li><li><a href="...">...</a></li>
|
// Generates: <li><a href="...">...</a></li><li><a href="...">...</a></li><li><a href="...">...</a></li>
|
||||||
```
|
```
|
||||||
|
|
||||||
### Return as an array
|
### Return as an Array
|
||||||
|
|
||||||
Perhaps you want an array instead of a string:
|
Perhaps you want an array instead of a string:
|
||||||
|
|
||||||
|
@ -118,21 +90,30 @@ print_r($lipsum->paragraphsArray(5));
|
||||||
You can still wrap with markup when returning an array:
|
You can still wrap with markup when returning an array:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
print_r($lipsum->wordsArray(5), 'li');
|
print_r($lipsum->wordsArray(5, 'li'));
|
||||||
```
|
```
|
||||||
|
|
||||||
## Assumptions
|
## Assumptions
|
||||||
|
|
||||||
Instead of having an option as to whether or not a string should start the
|
The first string generated will always start with the traditional "Lorem ipsum
|
||||||
generated output with “Lorem ipsum dolor sit amet, consectetur adipiscing
|
dolor sit amet, consectetur adipiscing elit". Subsequent strings may contain
|
||||||
elit.” a few assumptions are baked in. The first string generated will always
|
|
||||||
start with the traditional “Lorem ipsum…”. Subsequent strings may contain
|
|
||||||
those words but will not explicitly start with them.
|
those words but will not explicitly start with them.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Suggestions and bug reports are always welcome, but karma points are earned
|
Suggestions and bug reports are always welcome, but karma points are earned for
|
||||||
for pull requests.
|
pull requests.
|
||||||
|
|
||||||
Unit tests are required for all contributions. You can run the test suite
|
Unit tests are required for all contributions. You can run the test suite from
|
||||||
from the `tests` directory simply by running `phpunit .`
|
the project's root directory simply by running `phpunit`.
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
|
||||||
|
`php-loremipsum` was originally inspired by
|
||||||
|
[badcow/lorem-ipsum](https://packagist.org/packages/badcow/lorem-ipsum) with a
|
||||||
|
goal of being a dependency free lorem ipsum generator with flexible generation
|
||||||
|
options.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT
|
||||||
|
|
20
codecov.yml
Normal file
20
codecov.yml
Normal file
|
@ -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
|
|
@ -1,23 +1,34 @@
|
||||||
{
|
{
|
||||||
"name": "joshtronic/php-loremipsum",
|
"name": "joshtronic/php-loremipsum",
|
||||||
"description": "Lorem ipsum generator in PHP without dependencies",
|
"description": "Lorem ipsum generator in PHP without dependencies",
|
||||||
"version": "1.0.0",
|
"version": "2.1.0",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"keywords": ["lorem", "ipsum", "generator"],
|
"keywords": [
|
||||||
"homepage": "https://github.com/joshtronic/php-loremipsum",
|
"lorem",
|
||||||
"license": "MIT",
|
"ipsum",
|
||||||
|
"generator"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/joshtronic/php-loremipsum",
|
||||||
|
"license": "MIT",
|
||||||
"authors": [{
|
"authors": [{
|
||||||
"name": "Josh Sherman",
|
"name": "Josh Sherman",
|
||||||
"email": "josh@gravityblvd.com",
|
"email": "hello@joshtronic.com",
|
||||||
"homepage": "http://joshtronic.com"
|
"homepage": "https://joshtronic.com"
|
||||||
}],
|
}],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.0"
|
"php": ">=5.3"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"satooshi/php-coveralls": "dev-master"
|
"phpunit/phpunit": "^4.8.36 || ^9.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {"joshtronic\\": "src/"}
|
"psr-4": {
|
||||||
|
"joshtronic\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"joshtronic\\Tests\\": "tests/"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
14
phpstan.neon
Normal file
14
phpstan.neon
Normal file
|
@ -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%%'
|
24
phpunit.xml
Normal file
24
phpunit.xml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit
|
||||||
|
bootstrap="vendor/autoload.php"
|
||||||
|
colors="true"
|
||||||
|
convertErrorsToExceptions="true"
|
||||||
|
convertNoticesToExceptions="true"
|
||||||
|
convertWarningsToExceptions="true"
|
||||||
|
failOnRisky="true"
|
||||||
|
stopOnError="true"
|
||||||
|
stopOnFailure="true"
|
||||||
|
stopOnIncomplete="true"
|
||||||
|
verbose="true"
|
||||||
|
>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Lorem Ipsum">
|
||||||
|
<directory>tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<filter>
|
||||||
|
<whitelist addUncoveredFilesFromWhitelist="true">
|
||||||
|
<directory>./src</directory>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
</phpunit>
|
|
@ -8,8 +8,8 @@
|
||||||
* Licensed under The MIT License.
|
* Licensed under The MIT License.
|
||||||
* Redistribution of these files must retain the above copyright notice.
|
* Redistribution of these files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @author Josh Sherman <josh@gravityblvd.com>
|
* @author Josh Sherman <hello@joshtronic.com>
|
||||||
* @copyright Copyright 2014, Josh Sherman
|
* @copyright Copyright 2014-2022 Josh Sherman
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html
|
* @license http://www.opensource.org/licenses/mit-license.html
|
||||||
* @link https://github.com/joshtronic/php-loremipsum
|
* @link https://github.com/joshtronic/php-loremipsum
|
||||||
*/
|
*/
|
||||||
|
@ -24,7 +24,7 @@ class LoremIpsum
|
||||||
* Whether or not we should be starting the string with "Lorem ipsum..."
|
* Whether or not we should be starting the string with "Lorem ipsum..."
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
* @var boolean
|
* @var mixed
|
||||||
*/
|
*/
|
||||||
private $first = true;
|
private $first = true;
|
||||||
|
|
||||||
|
@ -35,57 +35,41 @@ class LoremIpsum
|
||||||
* a complete list exists and if so, where to get it.
|
* a complete list exists and if so, where to get it.
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
* @var array
|
* @var array<string>
|
||||||
*/
|
*/
|
||||||
public $words = array(
|
private $words = array(
|
||||||
// Lorem ipsum...
|
// Lorem ipsum...
|
||||||
'lorem', 'ipsum', 'dolor', 'sit',
|
'lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit',
|
||||||
'amet', 'consectetur', 'adipiscing', 'elit',
|
|
||||||
// The rest of the vocabulary
|
// and the rest of the vocabulary
|
||||||
'a', 'ac', 'accumsan', 'ad',
|
'a', 'ac', 'accumsan', 'ad', 'aenean', 'aliquam', 'aliquet', 'ante',
|
||||||
'aenean', 'aliquam', 'aliquet', 'ante',
|
'aptent', 'arcu', 'at', 'auctor', 'augue', 'bibendum', 'blandit',
|
||||||
'aptent', 'arcu', 'at', 'auctor',
|
'class', 'commodo', 'condimentum', 'congue', 'consequat', 'conubia',
|
||||||
'augue', 'bibendum', 'blandit', 'class',
|
'convallis', 'cras', 'cubilia', 'curabitur', 'curae', 'cursus',
|
||||||
'commodo', 'condimentum', 'congue', 'consequat',
|
'dapibus', 'diam', 'dictum', 'dictumst', 'dignissim', 'dis', 'donec',
|
||||||
'conubia', 'convallis', 'cras', 'cubilia',
|
'dui', 'duis', 'efficitur', 'egestas', 'eget', 'eleifend', 'elementum',
|
||||||
'cum', 'curabitur', 'curae', 'cursus',
|
'enim', 'erat', 'eros', 'est', 'et', 'etiam', 'eu', 'euismod', 'ex',
|
||||||
'dapibus', 'diam', 'dictum', 'dictumst',
|
'facilisi', 'facilisis', 'fames', 'faucibus', 'felis', 'fermentum',
|
||||||
'dignissim', 'dis', 'donec', 'dui',
|
'feugiat', 'finibus', 'fringilla', 'fusce', 'gravida', 'habitant',
|
||||||
'duis', 'egestas', 'eget', 'eleifend',
|
'habitasse', 'hac', 'hendrerit', 'himenaeos', 'iaculis', 'id',
|
||||||
'elementum', 'enim', 'erat', 'eros',
|
'imperdiet', 'in', 'inceptos', 'integer', 'interdum', 'justo',
|
||||||
'est', 'et', 'etiam', 'eu',
|
'lacinia', 'lacus', 'laoreet', 'lectus', 'leo', 'libero', 'ligula',
|
||||||
'euismod', 'facilisi', 'facilisis', 'fames',
|
'litora', 'lobortis', 'luctus', 'maecenas', 'magna', 'magnis',
|
||||||
'faucibus', 'felis', 'fermentum', 'feugiat',
|
'malesuada', 'massa', 'mattis', 'mauris', 'maximus', 'metus', 'mi',
|
||||||
'fringilla', 'fusce', 'gravida', 'habitant',
|
'molestie', 'mollis', 'montes', 'morbi', 'mus', 'nam', 'nascetur',
|
||||||
'habitasse', 'hac', 'hendrerit', 'himenaeos',
|
'natoque', 'nec', 'neque', 'netus', 'nibh', 'nisi', 'nisl', 'non',
|
||||||
'iaculis', 'id', 'imperdiet', 'in',
|
'nostra', 'nulla', 'nullam', 'nunc', 'odio', 'orci', 'ornare',
|
||||||
'inceptos', 'integer', 'interdum', 'justo',
|
'parturient', 'pellentesque', 'penatibus', 'per', 'pharetra',
|
||||||
'lacinia', 'lacus', 'laoreet', 'lectus',
|
'phasellus', 'placerat', 'platea', 'porta', 'porttitor', 'posuere',
|
||||||
'leo', 'libero', 'ligula', 'litora',
|
'potenti', 'praesent', 'pretium', 'primis', 'proin', 'pulvinar',
|
||||||
'lobortis', 'luctus', 'maecenas', 'magna',
|
'purus', 'quam', 'quis', 'quisque', 'rhoncus', 'ridiculus', 'risus',
|
||||||
'magnis', 'malesuada', 'massa', 'mattis',
|
'rutrum', 'sagittis', 'sapien', 'scelerisque', 'sed', 'sem', 'semper',
|
||||||
'mauris', 'metus', 'mi', 'molestie',
|
'senectus', 'sociosqu', 'sodales', 'sollicitudin', 'suscipit',
|
||||||
'mollis', 'montes', 'morbi', 'mus',
|
'suspendisse', 'taciti', 'tellus', 'tempor', 'tempus', 'tincidunt',
|
||||||
'nam', 'nascetur', 'natoque', 'nec',
|
'torquent', 'tortor', 'tristique', 'turpis', 'ullamcorper', 'ultrices',
|
||||||
'neque', 'netus', 'nibh', 'nisi',
|
'ultricies', 'urna', 'ut', 'varius', 'vehicula', 'vel', 'velit',
|
||||||
'nisl', 'non', 'nostra', 'nulla',
|
'venenatis', 'vestibulum', 'vitae', 'vivamus', 'viverra', 'volutpat',
|
||||||
'nullam', 'nunc', 'odio', 'orci',
|
'vulputate',
|
||||||
'ornare', 'parturient', 'pellentesque', 'penatibus',
|
|
||||||
'per', 'pharetra', 'phasellus', 'placerat',
|
|
||||||
'platea', 'porta', 'porttitor', 'posuere',
|
|
||||||
'potenti', 'praesent', 'pretium', 'primis',
|
|
||||||
'proin', 'pulvinar', 'purus', 'quam',
|
|
||||||
'quis', 'quisque', 'rhoncus', 'ridiculus',
|
|
||||||
'risus', 'rutrum', 'sagittis', 'sapien',
|
|
||||||
'scelerisque', 'sed', 'sem', 'semper',
|
|
||||||
'senectus', 'sociis', 'sociosqu', 'sodales',
|
|
||||||
'sollicitudin', 'suscipit', 'suspendisse', 'taciti',
|
|
||||||
'tellus', 'tempor', 'tempus', 'tincidunt',
|
|
||||||
'torquent', 'tortor', 'tristique', 'turpis',
|
|
||||||
'ullamcorper', 'ultrices', 'ultricies', 'urna',
|
|
||||||
'ut', 'varius', 'vehicula', 'vel',
|
|
||||||
'velit', 'venenatis', 'vestibulum', 'vitae',
|
|
||||||
'vivamus', 'viverra', 'volutpat', 'vulputate',
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,7 +83,7 @@ class LoremIpsum
|
||||||
*/
|
*/
|
||||||
public function word($tags = false)
|
public function word($tags = false)
|
||||||
{
|
{
|
||||||
return $this->words(1, $tags);
|
return strval($this->words(1, $tags));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,7 +94,7 @@ class LoremIpsum
|
||||||
* @access public
|
* @access public
|
||||||
* @param integer $count how many words to generate
|
* @param integer $count how many words to generate
|
||||||
* @param mixed $tags string or array of HTML tags to wrap output with
|
* @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)
|
public function wordsArray($count = 1, $tags = false)
|
||||||
{
|
{
|
||||||
|
@ -130,23 +114,21 @@ class LoremIpsum
|
||||||
*/
|
*/
|
||||||
public function words($count = 1, $tags = false, $array = false)
|
public function words($count = 1, $tags = false, $array = false)
|
||||||
{
|
{
|
||||||
|
$count = (int) $count;
|
||||||
$words = array();
|
$words = array();
|
||||||
$word_count = 0;
|
$word_count = 0;
|
||||||
|
|
||||||
// Shuffles and appends the word list to compensate for count
|
// Shuffles and appends the word list to compensate for count
|
||||||
// arguments that exceed the size of our vocabulary list
|
// arguments that exceed the size of our vocabulary list
|
||||||
while ($word_count < $count)
|
while ($word_count < $count) {
|
||||||
{
|
|
||||||
$shuffle = true;
|
$shuffle = true;
|
||||||
|
|
||||||
while ($shuffle)
|
while ($shuffle) {
|
||||||
{
|
|
||||||
$this->shuffle();
|
$this->shuffle();
|
||||||
|
|
||||||
// Checks that the last word of the list and the first word of
|
// Checks that the last word of the list and the first word of
|
||||||
// the list that's about to be appended are not the same
|
// the list that's about to be appended are not the same
|
||||||
if (!$word_count || $words[$word_count - 1] != $this->words[0])
|
if (!$word_count || $words[$word_count - 1] != $this->words[0]) {
|
||||||
{
|
|
||||||
$words = array_merge($words, $this->words);
|
$words = array_merge($words, $this->words);
|
||||||
$word_count = count($words);
|
$word_count = count($words);
|
||||||
$shuffle = false;
|
$shuffle = false;
|
||||||
|
@ -170,7 +152,7 @@ class LoremIpsum
|
||||||
*/
|
*/
|
||||||
public function sentence($tags = false)
|
public function sentence($tags = false)
|
||||||
{
|
{
|
||||||
return $this->sentences(1, $tags);
|
return strval($this->sentences(1, $tags));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -181,7 +163,7 @@ class LoremIpsum
|
||||||
* @access public
|
* @access public
|
||||||
* @param integer $count how many sentences to generate
|
* @param integer $count how many sentences to generate
|
||||||
* @param mixed $tags string or array of HTML tags to wrap output with
|
* @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)
|
public function sentencesArray($count = 1, $tags = false)
|
||||||
{
|
{
|
||||||
|
@ -203,8 +185,7 @@ class LoremIpsum
|
||||||
{
|
{
|
||||||
$sentences = array();
|
$sentences = array();
|
||||||
|
|
||||||
for ($i = 0; $i < $count; $i++)
|
for ($i = 0; $i < $count; $i++) {
|
||||||
{
|
|
||||||
$sentences[] = $this->wordsArray($this->gauss(24.46, 5.08));
|
$sentences[] = $this->wordsArray($this->gauss(24.46, 5.08));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +205,7 @@ class LoremIpsum
|
||||||
*/
|
*/
|
||||||
public function paragraph($tags = false)
|
public function paragraph($tags = false)
|
||||||
{
|
{
|
||||||
return $this->paragraphs(1, $tags);
|
return strval($this->paragraphs(1, $tags));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -235,15 +216,18 @@ class LoremIpsum
|
||||||
* @access public
|
* @access public
|
||||||
* @param integer $count how many paragraphs to generate
|
* @param integer $count how many paragraphs to generate
|
||||||
* @param mixed $tags string or array of HTML tags to wrap output with
|
* @param mixed $tags string or array of HTML tags to wrap output with
|
||||||
* @return array generated lorem ipsum paragraphs
|
* @return array<string> generated lorem ipsum paragraphs
|
||||||
*/
|
*/
|
||||||
public function paragraphsArray($count = 1, $tags = false)
|
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);
|
return $this->paragraphs($count, $tags, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paragraphss
|
* Paragraphs
|
||||||
*
|
*
|
||||||
* Generates paragraphs of lorem ipsum.
|
* Generates paragraphs of lorem ipsum.
|
||||||
*
|
*
|
||||||
|
@ -257,12 +241,14 @@ class LoremIpsum
|
||||||
{
|
{
|
||||||
$paragraphs = array();
|
$paragraphs = array();
|
||||||
|
|
||||||
for ($i = 0; $i < $count; $i++)
|
for ($i = 0; $i < $count; $i++) {
|
||||||
{
|
$paragraphs[] = strval($this->sentences($this->gauss(5.8, 1.93)));
|
||||||
$paragraphs[] = $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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -276,7 +262,7 @@ class LoremIpsum
|
||||||
* @access private
|
* @access private
|
||||||
* @param double $mean average value
|
* @param double $mean average value
|
||||||
* @param double $std_dev stadnard deviation
|
* @param double $std_dev stadnard deviation
|
||||||
* @return double calculated distribution
|
* @return int calculated distribution
|
||||||
*/
|
*/
|
||||||
private function gauss($mean, $std_dev)
|
private function gauss($mean, $std_dev)
|
||||||
{
|
{
|
||||||
|
@ -284,7 +270,7 @@ class LoremIpsum
|
||||||
$y = mt_rand() / mt_getrandmax();
|
$y = mt_rand() / mt_getrandmax();
|
||||||
$z = sqrt(-2 * log($x)) * cos(2 * pi() * $y);
|
$z = sqrt(-2 * log($x)) * cos(2 * pi() * $y);
|
||||||
|
|
||||||
return $z * $std_dev + $mean;
|
return intval($z * $std_dev + $mean);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -294,11 +280,11 @@ class LoremIpsum
|
||||||
* the first time we are generating the text.
|
* the first time we are generating the text.
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function shuffle()
|
private function shuffle()
|
||||||
{
|
{
|
||||||
if ($this->first)
|
if ($this->first) {
|
||||||
{
|
|
||||||
$this->first = array_slice($this->words, 0, 8);
|
$this->first = array_slice($this->words, 0, 8);
|
||||||
$this->words = array_slice($this->words, 8);
|
$this->words = array_slice($this->words, 8);
|
||||||
|
|
||||||
|
@ -307,9 +293,7 @@ class LoremIpsum
|
||||||
$this->words = $this->first + $this->words;
|
$this->words = $this->first + $this->words;
|
||||||
|
|
||||||
$this->first = false;
|
$this->first = false;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
shuffle($this->words);
|
shuffle($this->words);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -322,27 +306,23 @@ class LoremIpsum
|
||||||
* first word of the sentence.
|
* first word of the sentence.
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
* @param array $sentences the sentences we would like to punctuate
|
* @param array<string> $sentences the sentences we would like to punctuate
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function punctuate(&$sentences)
|
private function punctuate(&$sentences)
|
||||||
{
|
{
|
||||||
foreach ($sentences as $key => $sentence)
|
foreach ($sentences as $key => $sentence) {
|
||||||
{
|
|
||||||
$words = count($sentence);
|
$words = count($sentence);
|
||||||
|
|
||||||
// Only worry about commas on sentences longer than 4 words
|
// Only worry about commas on sentences longer than 4 words
|
||||||
if ($words > 4)
|
if ($words > 4) {
|
||||||
{
|
|
||||||
$mean = log($words, 6);
|
$mean = log($words, 6);
|
||||||
$std_dev = $mean / 6;
|
$std_dev = $mean / 6;
|
||||||
$commas = round($this->gauss($mean, $std_dev));
|
$commas = $this->gauss($mean, $std_dev);
|
||||||
|
|
||||||
for ($i = 1; $i <= $commas; $i++)
|
for ($i = 1; $i <= $commas; $i++) {
|
||||||
{
|
|
||||||
$word = round($i * $words / ($commas + 1));
|
$word = round($i * $words / ($commas + 1));
|
||||||
|
|
||||||
if ($word < ($words - 1) && $word > 0)
|
if ($word < ($words - 1) && $word > 0) {
|
||||||
{
|
|
||||||
$sentence[$word] .= ',';
|
$sentence[$word] .= ',';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -361,7 +341,7 @@ class LoremIpsum
|
||||||
* into a string or not.
|
* into a string or not.
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
* @param array $strings an array of generated strings
|
* @param array<string> $strings an array of generated strings
|
||||||
* @param mixed $tags string or array of HTML tags to wrap output with
|
* @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 boolean $array whether an array or a string should be returned
|
||||||
* @param string $delimiter the string to use when calling implode()
|
* @param string $delimiter the string to use when calling implode()
|
||||||
|
@ -369,30 +349,23 @@ class LoremIpsum
|
||||||
*/
|
*/
|
||||||
private function output($strings, $tags, $array, $delimiter = ' ')
|
private function output($strings, $tags, $array, $delimiter = ' ')
|
||||||
{
|
{
|
||||||
if ($tags)
|
if ($tags) {
|
||||||
{
|
if (!is_array($tags)) {
|
||||||
if (!is_array($tags))
|
|
||||||
{
|
|
||||||
$tags = array($tags);
|
$tags = array($tags);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// Flips the array so we can work from the inside out
|
// Flips the array so we can work from the inside out
|
||||||
$tags = array_reverse($tags);
|
$tags = array_reverse($tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($strings as $key => $string)
|
foreach ($strings as $key => $string) {
|
||||||
{
|
foreach ($tags as $tag) {
|
||||||
foreach ($tags as $tag)
|
if (is_string($tag)) {
|
||||||
{
|
// Detects / applies back reference
|
||||||
// Detects / applies back reference
|
if ($tag[0] == '<') {
|
||||||
if ($tag[0] == '<')
|
$string = str_replace('$1', $string, $tag);
|
||||||
{
|
} else {
|
||||||
$string = str_replace('$1', $string, $tag);
|
$string = sprintf('<%1$s>%2$s</%1$s>', $tag, $string);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
$string = sprintf('<%1$s>%2$s</%1$s>', $tag, $string);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$strings[$key] = $string;
|
$strings[$key] = $string;
|
||||||
|
@ -400,12 +373,10 @@ class LoremIpsum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$array)
|
if (!$array) {
|
||||||
{
|
|
||||||
$strings = implode($delimiter, $strings);
|
$strings = implode($delimiter, $strings);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $strings;
|
return $strings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,127 +1,198 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace joshtronic\Tests;
|
||||||
|
use joshtronic\LoremIpsum;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
require_once '../src/LoremIpsum.php';
|
class LoremIpsumTest extends TestCase
|
||||||
|
|
||||||
class LoremIpsumTest extends PHPUnit_Framework_TestCase
|
|
||||||
{
|
{
|
||||||
private $lipsum;
|
/**
|
||||||
|
* @doesNotPerformAssertions
|
||||||
|
*/
|
||||||
|
public function testAssertRegExp() {
|
||||||
|
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||||
|
return 'assertMatchesRegularExpression';
|
||||||
|
}
|
||||||
|
|
||||||
public function setUp()
|
return 'assertRegExp';
|
||||||
{
|
|
||||||
$this->lipsum = new joshtronic\LoremIpsum();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWord()
|
/**
|
||||||
|
* @depends testAssertRegExp
|
||||||
|
*/
|
||||||
|
public function testWord($assertRegExp)
|
||||||
{
|
{
|
||||||
$this->assertRegExp('/^[a-z]+$/i', $this->lipsum->word());
|
$lipsum = new LoremIpsum();
|
||||||
|
$this->$assertRegExp('/^[a-z]+$/i', $lipsum->word());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWords()
|
/**
|
||||||
|
* @depends testAssertRegExp
|
||||||
|
*/
|
||||||
|
public function testWords($assertRegExp)
|
||||||
{
|
{
|
||||||
$this->assertRegExp(
|
$lipsum = new LoremIpsum();
|
||||||
|
$this->$assertRegExp(
|
||||||
'/^[a-z]+ [a-z]+ [a-z]+$/i',
|
'/^[a-z]+ [a-z]+ [a-z]+$/i',
|
||||||
$this->lipsum->words(3)
|
$lipsum->words(3)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWordsArray()
|
/**
|
||||||
|
* @depends testAssertRegExp
|
||||||
|
*/
|
||||||
|
public function testWordsArray($assertRegExp)
|
||||||
{
|
{
|
||||||
$words = $this->lipsum->wordsArray(3);
|
$lipsum = new LoremIpsum();
|
||||||
|
$words = $lipsum->wordsArray(3);
|
||||||
$this->assertTrue(is_array($words));
|
$this->assertTrue(is_array($words));
|
||||||
$this->assertCount(3, $words);
|
$this->assertCount(3, $words);
|
||||||
|
|
||||||
foreach ($words as $word)
|
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)
|
||||||
{
|
{
|
||||||
$this->assertCount(500, $this->lipsum->wordsArray(500));
|
$lipsum = new LoremIpsum();
|
||||||
|
$this->assertCount(500, $lipsum->wordsArray(500));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSentence()
|
/**
|
||||||
|
* @depends testAssertRegExp
|
||||||
|
*/
|
||||||
|
public function testSentence($assertRegExp)
|
||||||
{
|
{
|
||||||
$this->assertRegExp('/^[a-z, ]+\.$/i', $this->lipsum->sentence());
|
$lipsum = new LoremIpsum();
|
||||||
|
$this->$assertRegExp('/^[a-z, ]+\.$/i', $lipsum->sentence());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSentences()
|
/**
|
||||||
|
* @depends testAssertRegExp
|
||||||
|
*/
|
||||||
|
public function testSentences($assertRegExp)
|
||||||
{
|
{
|
||||||
$this->assertRegExp('/^[a-z, ]+\. [a-z, ]+\. [a-z, ]+\.$/i', $this->lipsum->sentences(3));
|
$lipsum = new LoremIpsum();
|
||||||
|
$this->$assertRegExp(
|
||||||
|
'/^[a-z, ]+\. [a-z, ]+\. [a-z, ]+\.$/i',
|
||||||
|
$lipsum->sentences(3)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSentencesArray()
|
/**
|
||||||
|
* @depends testAssertRegExp
|
||||||
|
*/
|
||||||
|
public function testSentencesArray($assertRegExp)
|
||||||
{
|
{
|
||||||
$sentences = $this->lipsum->sentencesArray(3);
|
$lipsum = new LoremIpsum();
|
||||||
|
$sentences = $lipsum->sentencesArray(3);
|
||||||
$this->assertTrue(is_array($sentences));
|
$this->assertTrue(is_array($sentences));
|
||||||
$this->assertCount(3, $sentences);
|
$this->assertCount(3, $sentences);
|
||||||
|
|
||||||
foreach ($sentences as $sentence)
|
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)
|
||||||
{
|
{
|
||||||
$this->assertRegExp('/^([a-z, ]+\.)+$/i', $this->lipsum->paragraph());
|
$lipsum = new LoremIpsum();
|
||||||
|
$this->$assertRegExp('/^([a-z, ]+\.)+$/i', $lipsum->paragraph());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testParagraphs()
|
/**
|
||||||
|
* @depends testAssertRegExp
|
||||||
|
*/
|
||||||
|
public function testParagraphs($assertRegExp)
|
||||||
{
|
{
|
||||||
$this->assertRegExp(
|
$lipsum = new LoremIpsum();
|
||||||
|
$this->$assertRegExp(
|
||||||
'/^([a-z, ]+\.)+\n\n([a-z, ]+\.)+\n\n([a-z, ]+\.)+$/i',
|
'/^([a-z, ]+\.)+\n\n([a-z, ]+\.)+\n\n([a-z, ]+\.)+$/i',
|
||||||
$this->lipsum->paragraphs(3)
|
$lipsum->paragraphs(3)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testParagraphsArray()
|
/**
|
||||||
|
* @depends testAssertRegExp
|
||||||
|
*/
|
||||||
|
public function testParagraphsArray($assertRegExp)
|
||||||
{
|
{
|
||||||
$paragraphs = $this->lipsum->paragraphsArray(3);
|
$lipsum = new LoremIpsum();
|
||||||
|
$paragraphs = $lipsum->paragraphsArray(3);
|
||||||
$this->assertTrue(is_array($paragraphs));
|
$this->assertTrue(is_array($paragraphs));
|
||||||
$this->assertCount(3, $paragraphs);
|
$this->assertCount(3, $paragraphs);
|
||||||
|
|
||||||
foreach ($paragraphs as $paragraph)
|
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)
|
||||||
{
|
{
|
||||||
$this->assertRegExp(
|
$lipsum = new LoremIpsum();
|
||||||
|
$this->$assertRegExp(
|
||||||
'/^<li>[a-z]+<\/li>$/i',
|
'/^<li>[a-z]+<\/li>$/i',
|
||||||
$this->lipsum->word('li')
|
$lipsum->word('li')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMarkupArray()
|
/**
|
||||||
|
* @depends testAssertRegExp
|
||||||
|
*/
|
||||||
|
public function testMarkupArray($assertRegExp)
|
||||||
{
|
{
|
||||||
$this->assertRegExp(
|
$lipsum = new LoremIpsum();
|
||||||
|
$this->$assertRegExp(
|
||||||
'/^<div><p>[a-z]+<\/p><\/div>$/i',
|
'/^<div><p>[a-z]+<\/p><\/div>$/i',
|
||||||
$this->lipsum->word(array('div', 'p'))
|
$lipsum->word(array('div', 'p'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMarkupBackReference()
|
/**
|
||||||
|
* @depends testAssertRegExp
|
||||||
|
*/
|
||||||
|
public function testMarkupBackReference($assertRegExp)
|
||||||
{
|
{
|
||||||
$this->assertRegExp(
|
$lipsum = new LoremIpsum();
|
||||||
|
$this->$assertRegExp(
|
||||||
'/^<li><a href="[a-z]+">[a-z]+<\/a><\/li>$/i',
|
'/^<li><a href="[a-z]+">[a-z]+<\/a><\/li>$/i',
|
||||||
$this->lipsum->word('<li><a href="$1">$1</a></li>')
|
$lipsum->word('<li><a href="$1">$1</a></li>')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMarkupArrayReturn()
|
/**
|
||||||
|
* @depends testAssertRegExp
|
||||||
|
*/
|
||||||
|
public function testMarkupArrayReturn($assertRegExp)
|
||||||
{
|
{
|
||||||
$words = $this->lipsum->wordsArray(3, 'li');
|
$lipsum = new LoremIpsum();
|
||||||
|
$words = $lipsum->wordsArray(3, 'li');
|
||||||
$this->assertTrue(is_array($words));
|
$this->assertTrue(is_array($words));
|
||||||
$this->assertCount(3, $words);
|
$this->assertCount(3, $words);
|
||||||
|
|
||||||
foreach ($words as $word)
|
foreach ($words as $word) {
|
||||||
{
|
$this->$assertRegExp('/^<li>[a-z]+<\/li>$/i', $word);
|
||||||
$this->assertRegExp('/^<li>[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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue