|
1
|
|
|
<?php namespace nyx\utils\tests; |
|
2
|
|
|
|
|
3
|
|
|
// Internal dependencies |
|
4
|
|
|
use nyx\utils\Str; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Str Tests |
|
8
|
|
|
* |
|
9
|
|
|
* @package Nyx\Utils\Tests |
|
10
|
|
|
* @version 0.0.1 |
|
11
|
|
|
* @author Michal Chojnacki <[email protected]> |
|
12
|
|
|
* @copyright 2012-2016 Nyx Dev Team |
|
13
|
|
|
* @link http://docs.muyo.io/nyx/utils/index.html |
|
14
|
|
|
*/ |
|
15
|
|
|
class StrTest extends \PHPUnit\Framework\TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
// Str::occurrences() |
|
|
|
|
|
|
18
|
|
|
public function testStrOccurrences() |
|
19
|
|
|
{ |
|
20
|
|
|
$source = 'foobarfoobarfoobar'; |
|
21
|
|
|
|
|
22
|
|
|
// Basic case-sensitive test |
|
23
|
|
|
$this->assertEquals([0, 6, 12], Str::occurrences($source, 'foobar', 0, true)); |
|
24
|
|
|
$this->assertEquals([], Str::occurrences($source, 'FOOBAR', 0, true)); |
|
25
|
|
|
|
|
26
|
|
|
// Case-insensitive |
|
27
|
|
|
$this->assertEquals([0, 6, 12], Str::occurrences($source, 'foobar', 0, false)); |
|
28
|
|
|
$this->assertEquals([0, 6, 12], Str::occurrences($source, 'FOOBAR', 0, false)); |
|
29
|
|
|
|
|
30
|
|
|
// Start at a positive offset within the $source |
|
31
|
|
|
$this->assertEquals([6, 12], Str::occurrences($source, 'foobar', 3)); |
|
32
|
|
|
$this->assertEquals([6, 12], Str::occurrences($source, 'foobar', 6)); |
|
33
|
|
|
$this->assertEquals([12], Str::occurrences($source, 'foobar', 9)); |
|
34
|
|
|
|
|
35
|
|
|
// Start at a negative offset within the $source |
|
36
|
|
|
$this->assertEquals([], Str::occurrences($source, 'foobar', -3)); |
|
37
|
|
|
$this->assertEquals([12], Str::occurrences($source, 'foobar', -6)); |
|
38
|
|
|
$this->assertEquals([12], Str::occurrences($source, 'foobar', -9)); |
|
39
|
|
|
$this->assertEquals([6, 12], Str::occurrences($source, 'foobar', -12)); |
|
40
|
|
|
|
|
41
|
|
|
// Start at an offset not within the $source |
|
42
|
|
|
$this->expectException('OutOfBoundsException'); |
|
43
|
|
|
Str::occurrences($source, 'foobar', 100); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.