Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#14)
by Der Mundschenk
02:42
created

Text_Parser_Test::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *  This file is part of PHP-Typography.
4
 *
5
 *  Copyright 2015-2017 Peter Putzer.
6
 *
7
 *  This program is free software; you can redistribute it and/or
8
 *  modify it under the terms of the GNU General Public License
9
 *  as published by the Free Software Foundation; either version 2
10
 *  of the License, or ( at your option ) any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program; if not, write to the Free Software
19
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 *
21
 *  @package mundschenk-at/php-typography/tests
22
 *  @license http://www.gnu.org/licenses/gpl-2.0.html
23
 */
24
25
namespace PHP_Typography\Tests;
26
27
use \PHP_Typography\Text_Parser\Token;
28
use \PHP_Typography\Text_Parser;
29
30
/**
31
 * Unit test for \PHP_Typography\Text_Parser class.
32
 *
33
 * @coversDefaultClass \PHP_Typography\Text_Parser
34
 * @usesDefaultClass \PHP_Typography\Text_Parser
35
 *
36
 * @uses PHP_Typography\Text_Parser::__construct
37
 * @uses PHP_Typography\Text_Parser\Token
38
 * @uses PHP_Typography\Strings::functions
39
 */
40
class Text_Parser_Test extends PHP_Typography_Testcase {
41
	/**
42
	 * The Text_Parser fixture.
43
	 *
44
	 * @var Text_Parser
45
	 */
46
	protected $parser;
47
48
	/**
49
	 * Sets up the fixture, for example, opens a network connection.
50
	 * This method is called before a test is executed.
51
	 */
52
	protected function setUp() {
53
		$this->parser = new \PHP_Typography\Text_Parser();
54
	}
55
56
	/**
57
	 * Tears down the fixture, for example, closes a network connection.
58
	 * This method is called after a test is executed.
59
	 */
60
	protected function tearDown() {
61
	}
62
63
	/**
64
	 * Test constructor.
65
	 *
66
	 * @covers ::__construct
67
	 */
68
	public function test_constructor() {
69
		$parser = new Text_Parser( [ 'UTF-8' ] );
0 ignored issues
show
Unused Code introduced by
The call to Text_Parser::__construct() has too many arguments starting with array('UTF-8').

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
70
71
		$this->assertAttributeCount( 0, 'text', $parser );
72
		$this->assertAttributeEmpty( 'current_strtoupper', $parser );
73
	}
74
75
	/**
76
	 * Test load.
77
	 *
78
	 * @covers ::load
79
	 * @covers ::tokenize
80
	 * @covers ::parse_ambiguous_token
81
	 * @covers ::is_preceeded_by
82
	 * @covers ::is_not_preceeded_by
83
	 *
84
	 * @uses ::get_all
85
	 */
86
	public function test_load() {
87
		$too_long = 'A really long string with a word that is wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalmost too long.';
89
		$almost_too_long = 'A really long string with a word that is aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalmost too long.';
90
91
		$parser = $this->parser;
92
93
		// Security check.
94
		$this->assertFalse( $parser->load( $too_long ) );
95
		$this->assertFalse( $parser->load( $still_too_long ) );
96
		$this->assertTrue( $parser->load( $almost_too_long ) );
97
98
		$interesting = 'Quoth the raven, "nevermore"! Äöüß?';
99
		$this->assertTrue( $parser->load( $interesting ) );
100
101
		$tokens = $parser->get_all();
102
103
		$this->assertCount( 13, $tokens );
104
		$this->assertArraySubset( [
105
			0 => new Token( 'Quoth', Token::WORD ),
106
		], $tokens );
107
		$this->assertArraySubset( [
108
			5 => new Token( ',', Token::PUNCTUATION ),
109
		], $tokens );
110
		$this->assertArraySubset( [
111
			11 => new Token( 'Äöüß', Token::WORD ),
112
		], $tokens );
113
114
		return $parser;
115
	}
116
117
	/**
118
	 * Test load with email address.
119
	 *
120
	 * @covers ::load
121
	 * @covers ::tokenize
122
	 * @covers ::parse_ambiguous_token
123
	 * @covers ::is_preceeded_by
124
	 * @covers ::is_not_preceeded_by
125
	 *
126
	 * @uses ::get_all
127
	 */
128 View Code Duplication
	public function test_load_email() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
129
		$parser = $this->parser;
130
131
		$string = 'Quoth the raven, "nevermore"! Please mail to [email protected].';
132
		$this->assertTrue( $parser->load( $string ) );
133
134
		$tokens = $parser->get_all();
135
		$this->assertCount( 19, $tokens );
136
137
		$this->assertArraySubset( [
138
			0 => new Token( 'Quoth', Token::WORD ),
139
		], $tokens );
140
		$this->assertArraySubset( [
141
			5 => new Token( ',', Token::PUNCTUATION ),
142
		], $tokens );
143
		$this->assertArraySubset( [
144
			17 => new Token( '[email protected]', Token::OTHER ),
145
		], $tokens );
146
147
		return $parser;
148
	}
149
150
	/**
151
	 * Test load with URL.
152
	 *
153
	 * @covers ::load
154
	 * @covers ::tokenize
155
	 * @covers ::parse_ambiguous_token
156
	 * @covers ::is_preceeded_by
157
	 * @covers ::is_not_preceeded_by
158
	 *
159
	 * @uses ::get_all
160
	 */
161
	public function test_load_url() {
162
		$parser = $this->parser;
163
164
		$string = 'Quoth the raven, "nevermore"! Please open http://example.org or foo:WordPress or foo:W@rdPress or @example or @:@:@:risk.';
165
		$this->assertTrue( $parser->load( $string ) );
166
167
		$tokens = $parser->get_all();
168
		$this->assertCount( 33, $tokens );
169
170
		$this->assertArraySubset( [
171
			0 => new Token( 'Quoth', Token::WORD ),
172
		], $tokens );
173
		$this->assertArraySubset( [
174
			5 => new Token( ',', Token::PUNCTUATION ),
175
		], $tokens );
176
		$this->assertArraySubset( [
177
			15 => new Token( 'http://example.org', Token::OTHER ),
178
		], $tokens );
179
		$this->assertArraySubset( [
180
			19 => new Token( 'foo:WordPress', Token::OTHER ),
181
		], $tokens );
182
		$this->assertArraySubset( [
183
			23 => new Token( 'foo:W@rdPress', Token::OTHER ),
184
		], $tokens );
185
		$this->assertArraySubset( [
186
			27 => new Token( '@example', Token::OTHER ),
187
		], $tokens );
188
		$this->assertArraySubset( [
189
			31 => new Token( '@:@:@:risk', Token::OTHER ),
190
		], $tokens );
191
192
		return $parser;
193
	}
194
195
	/**
196
	 * Test load with a compound word.
197
	 *
198
	 * @covers ::load
199
	 * @covers ::tokenize
200
	 * @covers ::parse_ambiguous_token
201
	 * @covers ::is_preceeded_by
202
	 * @covers ::is_not_preceeded_by
203
	 *
204
	 * @uses ::get_all
205
	 */
206 View Code Duplication
	public function test_load_compound_word() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
207
		$parser = $this->parser;
208
209
		$string = 'Some don\'t trust the captain-owner.';
210
		$this->assertTrue( $parser->load( $string ) );
211
212
		$tokens = $parser->get_all();
213
		$this->assertCount( 10, $tokens );
214
215
		$this->assertArraySubset( [
216
			0 => new Token( 'Some', Token::WORD ),
217
		], $tokens );
218
		$this->assertArraySubset( [
219
			2 => new Token( "don't", Token::OTHER ),
220
		], $tokens );
221
		$this->assertArraySubset( [
222
			8 => new Token( 'captain-owner', Token::WORD ),
223
		], $tokens );
224
225
		return $parser;
226
	}
227
228
	/**
229
	 * Test load with an invalid encoding.
230
	 *
231
	 * @covers ::load
232
	 */
233
	public function test_load_invalid_encoding() {
234
		$string = mb_convert_encoding( 'Ein längerer String im falschen Zeichensatz', 'ISO-8859-2' );
235
		$parser = $this->parser;
236
237
		$this->assertFalse( $parser->load( $string ) );
238
	}
239
240
	/**
241
	 * Test load with something that is not a string.
242
	 *
243
	 * @covers ::load
244
	 */
245
	public function test_load_not_a_string() {
246
		$parser = $this->parser;
247
248
		$this->assertFalse( $parser->load( [] ) );
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
249
	}
250
251
	/**
252
	 * Test reload.
253
	 *
254
	 * @covers ::reload
255
	 *
256
	 * @depends test_load
257
	 * @uses ::clear
258
	 * @uses ::get_all
259
	 * @uses ::is_not_preceeded_by
260
	 * @uses ::is_preceeded_by
261
	 * @uses ::load
262
	 * @uses ::parse_ambiguous_token
263
	 * @uses ::tokenize
264
	 * @uses ::unload
265
	 * @uses ::update
266
267
	 * @param \PHP_Typography\Text_Parser $parser The parser to use.
268
	 */
269
	public function test_reload( Text_Parser $parser ) {
270
		$tokens = $parser->get_all();
271
		$tokens[12] = $tokens[12]->with_value( '' ); // ?.
272
		$tokens[11] = $tokens[11]->with_value( '' ); // Äöüß
273
		$tokens[10] = $tokens[10]->with_value( '' ); //
274
		$tokens[9]  = $tokens[9]->with_value( $tokens[9]->value . '!' );
275
		$parser->update( $tokens );
276
277
		$this->assertTrue( $parser->reload() );
278
		$this->assertSame( 'Quoth the raven, "nevermore"!!', $parser->unload() );
279
280
		return $parser;
281
	}
282
283
	/**
284
	 * Test unload.
285
	 *
286
	 * @covers ::unload
287
	 *
288
	 * @uses ::clear
289
	 * @uses ::is_not_preceeded_by
290
	 * @uses ::is_preceeded_by
291
	 * @uses ::load
292
	 * @uses ::parse_ambiguous_token
293
	 * @uses ::tokenize
294
	 */
295
	public function test_unload() {
296
		$interesting = 'Quoth the raven, "nevermore"! Äöüß?';
297
		$parser = $this->parser;
298
299
		$this->assertTrue( $parser->load( $interesting ) );
300
301
		$result = $parser->unload();
302
303
		$this->assertSame( $interesting, $result );
304
		$this->assertNotSame( $result, $parser->unload() ); // the parser is empty now.
305
	}
306
307
	/**
308
	 * Test clear.
309
	 *
310
	 * @covers ::clear
311
	 *
312
	 * @uses ::get_all
313
	 * @uses ::is_not_preceeded_by
314
	 * @uses ::is_preceeded_by
315
	 * @uses ::load
316
	 * @uses ::parse_ambiguous_token
317
	 * @uses ::tokenize
318
	 */
319
	public function test_clear() {
320
		$parser = $this->parser;
321
		$interesting = 'Quoth the raven, "nevermore"!';
322
323
		$this->assertTrue( $parser->load( $interesting ) );
324
		$this->assertGreaterThan( 0, count( $parser->get_all() ) );
325
326
		$parser->clear();
327
		$this->assertCount( 0, $parser->get_all() );
328
	}
329
330
	/**
331
	 * Test update.
332
	 *
333
	 * @covers ::update
334
	 *
335
	 * @uses ::clear
336
	 * @uses ::get_all
337
	 * @uses ::is_not_preceeded_by
338
	 * @uses ::is_preceeded_by
339
	 * @uses ::load
340
	 * @uses ::parse_ambiguous_token
341
	 * @uses ::tokenize
342
	 * @uses ::unload
343
	 */
344
	public function test_update() {
345
		$parser = $this->parser;
346
		$interesting = 'Quoth the raven, "nevermore"! Äöüß?';
347
		$this->assertTrue( $parser->load( $interesting ) );
348
349
		$tokens = $parser->get_all();
350
		$tokens[12] = $tokens[12]->with_value( '' ); // ?.
351
		$tokens[11] = $tokens[11]->with_value( '' ); // Äöüß
352
		$tokens[10] = $tokens[10]->with_value( '' ); //
353
		$tokens[9]  = $tokens[9]->with_value( $tokens[9]->value . '!' );
354
		$parser->update( $tokens );
355
356
		$this->assertSame( 'Quoth the raven, "nevermore"!!', $parser->unload() );
357
358
		return $parser;
359
	}
360
361
	/**
362
	 * Test get_all.
363
	 *
364
	 * @covers ::get_all
365
	 *
366
	 * @uses ::load
367
	 * @uses ::is_not_preceeded_by
368
	 * @uses ::is_preceeded_by
369
	 * @uses ::parse_ambiguous_token
370
	 * @uses ::tokenize
371
	 */
372
	public function test_get_all() {
373
		$interesting = 'Quoth the raven, "nevermore"!';
374
		$parser = $this->parser;
375
		$this->assertTrue( $parser->load( $interesting ) );
376
377
		$tokens = $parser->get_all();
378
		$this->assertCount( 10, $tokens );
379
380
		return $parser;
381
	}
382
383
	/**
384
	 * Test get_spaces.
385
	 *
386
	 * @covers ::get_spaces
387
	 * @depends test_get_all
388
	 *
389
	 * @uses ::get_type
390
	 *
391
	 * @param \PHP_Typography\Text_Parser $parser The parser to use.
392
	 */
393
	public function test_get_spaces( Text_Parser $parser ) {
394
		$tokens = $parser->get_spaces();
395
		$this->assertCount( 3, $tokens );
396
397
		return $parser;
398
	}
399
400
	/**
401
	 * Test get_punctuation.
402
	 *
403
	 * @covers ::get_punctuation
404
	 * @depends test_get_all
405
	 *
406
	 * @uses ::get_type
407
	 *
408
	 * @param \PHP_Typography\Text_Parser $parser The parser to use.
409
	 */
410
	public function test_get_punctuation( Text_Parser $parser ) {
411
		$tokens = $parser->get_punctuation();
412
		$this->assertCount( 3, $tokens );
413
414
		return $parser;
415
	}
416
417
	/**
418
	 * Test get_words.
419
	 *
420
	 * @covers ::get_words
421
	 * @depends test_get_all
422
	 *
423
	 * @uses ::conforms_to_caps_policy
424
	 * @uses ::conforms_to_compounds_policy
425
	 * @uses ::conforms_to_letters_policy
426
	 * @uses ::get_type
427
	 * @uses ::is_preceeded_by
428
	 * @uses ::load
429
	 * @uses ::parse_ambiguous_token
430
	 * @uses ::tokenize
431
	 *
432
	 * @param \PHP_Typography\Text_Parser $parser The parser to use.
433
	 */
434
	public function test_get_words( Text_Parser $parser ) {
435
		$tokens = $parser->get_words();
436
		$this->assertCount( 4, $tokens );
437
438
		$parser->load( 'A few m1xed W0RDS.' );
439
		$tokens = $parser->get_words( Text_Parser::REQUIRE_ALL_LETTERS, Text_Parser::NO_ALL_CAPS );
440
		$this->assertCount( 1, $tokens );
441
		$this->assertContains( new Token( 'few', Token::WORD ), $tokens, '', false, false, true );
442
443
		$tokens = $parser->get_words( Text_Parser::ALLOW_ALL_LETTERS, Text_Parser::NO_ALL_CAPS );
444
		$this->assertCount( 2, $tokens );
445
		$this->assertContains( new Token( 'few', Token::WORD ), $tokens, '', false, false, true );
446
		$this->assertContains( new Token( 'm1xed', Token::WORD ), $tokens, '', false, false, true );
447
448
		$tokens = $parser->get_words( Text_Parser::NO_ALL_LETTERS, Text_Parser::NO_ALL_CAPS );
449
		$this->assertCount( 1, $tokens );
450
		$this->assertContains( new Token( 'm1xed', Token::WORD ), $tokens, '', false, false, true );
451
452
		$tokens = $parser->get_words( Text_Parser::REQUIRE_ALL_LETTERS, Text_Parser::ALLOW_ALL_CAPS );
453
		$this->assertCount( 2, $tokens );
454
		$this->assertContains( new Token( 'A', Token::WORD ), $tokens, '', false, false, true );
455
		$this->assertContains( new Token( 'few', Token::WORD ), $tokens, '', false, false, true );
456
457
		$tokens = $parser->get_words( Text_Parser::ALLOW_ALL_LETTERS, Text_Parser::ALLOW_ALL_CAPS );
458
		$this->assertCount( 4, $tokens );
459
		$this->assertContains( new Token( 'A', Token::WORD ), $tokens, '', false, false, true );
460
		$this->assertContains( new Token( 'few', Token::WORD ), $tokens, '', false, false, true );
461
		$this->assertContains( new Token( 'm1xed', Token::WORD ), $tokens, '', false, false, true );
462
		$this->assertContains( new Token( 'W0RDS', Token::WORD ), $tokens, '', false, false, true );
463
464
		$tokens = $parser->get_words( Text_Parser::NO_ALL_LETTERS, Text_Parser::ALLOW_ALL_CAPS );
465
		$this->assertCount( 2, $tokens );
466
		$this->assertContains( new Token( 'm1xed', Token::WORD ), $tokens, '', false, false, true );
467
		$this->assertContains( new Token( 'W0RDS', Token::WORD ), $tokens, '', false, false, true );
468
469
		$tokens = $parser->get_words( Text_Parser::REQUIRE_ALL_LETTERS, Text_Parser::REQUIRE_ALL_CAPS );
470
		$this->assertCount( 1, $tokens );
471
		$this->assertContains( new Token( 'A', Token::WORD ), $tokens, '', false, false, true );
472
473
		$tokens = $parser->get_words( Text_Parser::ALLOW_ALL_LETTERS, Text_Parser::REQUIRE_ALL_CAPS );
474
		$this->assertCount( 2, $tokens );
475
		$this->assertContains( new Token( 'A', Token::WORD ), $tokens, '', false, false, true );
476
		$this->assertContains( new Token( 'W0RDS', Token::WORD ), $tokens, '', false, false, true );
477
478
		$tokens = $parser->get_words( Text_Parser::NO_ALL_LETTERS, Text_Parser::REQUIRE_ALL_CAPS );
479
		$this->assertCount( 1, $tokens );
480
		$this->assertContains( new Token( 'W0RDS', Token::WORD ), $tokens, '', false, false, true );
481
	}
482
483
	/**
484
	 * Providate data for testing conforms_to_letters_policy.
485
	 *
486
	 * @return array
487
	 */
488 View Code Duplication
	public function provide_conforms_to_letters_policy_data() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
489
		return [
490
			[ 'simple',   Token::WORD, Text_Parser::ALLOW_ALL_LETTERS, true ],
491
			[ 'SIMPLE',   Token::WORD, Text_Parser::ALLOW_ALL_LETTERS, true ],
492
			[ 'simple',   Token::WORD, Text_Parser::NO_ALL_LETTERS, false ],
493
			[ 'simple99', Token::WORD, Text_Parser::NO_ALL_LETTERS, true ],
494
			[ 'simple',   Token::WORD, Text_Parser::REQUIRE_ALL_LETTERS, true ],
495
			[ 'SIMPLE',   Token::WORD, Text_Parser::REQUIRE_ALL_LETTERS, true ],
496
			[ 'SIMPLE99', Token::WORD, Text_Parser::REQUIRE_ALL_LETTERS, false ],
497
			[ 'simple99', Token::WORD, Text_Parser::ALLOW_ALL_LETTERS, true ],
498
			[ 'SIM-PLE',  Token::WORD, Text_Parser::ALLOW_ALL_LETTERS, true ],
499
			[ 'sim-ple',  Token::WORD, Text_Parser::NO_ALL_LETTERS, true ],
500
			[ 'SIM-PLE',  Token::WORD, Text_Parser::NO_ALL_LETTERS, true ],
501
			[ 'sim-ple',  Token::WORD, Text_Parser::REQUIRE_ALL_LETTERS, false ],
502
			[ 'SIM-PLE',  Token::WORD, Text_Parser::REQUIRE_ALL_LETTERS, false ],
503
		];
504
	}
505
506
	/**
507
	 * Test conforms_to_letters_policy.
508
	 *
509
	 * @covers ::conforms_to_letters_policy
510
	 * @dataProvider provide_conforms_to_letters_policy_data
511
	 *
512
	 * @uses ::load
513
	 * @uses ::is_preceeded_by
514
	 * @uses ::parse_ambiguous_token
515
	 * @uses ::tokenize
516
	 *
517
	 * @param string $value  Token value.
518
	 * @param int    $type   Token type.
519
	 * @param int    $policy Letters policy.
520
	 * @param bool   $result Expected result.
521
	 */
522
	public function test_conforms_to_letters_policy( $value, $type, $policy, $result ) {
523
		$parser = $this->parser;
524
		$token  = new Token( $value, $type );
525
526
		$this->assertSame( $result, $this->invokeMethod( $parser, 'conforms_to_letters_policy', [ $token, $policy ] ) );
527
	}
528
529
	/**
530
	 * Providate data for testing conforms_to_caps_policy.
531
	 *
532
	 * @return array
533
	 */
534 View Code Duplication
	public function provide_conforms_to_caps_policy_data() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
535
		return [
536
			[ 'simple',   Token::WORD, Text_Parser::ALLOW_ALL_CAPS, true ],
537
			[ 'SIMPLE',   Token::WORD, Text_Parser::ALLOW_ALL_CAPS, true ],
538
			[ 'simple',   Token::WORD, Text_Parser::NO_ALL_CAPS, true ],
539
			[ 'simple99', Token::WORD, Text_Parser::NO_ALL_CAPS, true ],
540
			[ 'simple',   Token::WORD, Text_Parser::REQUIRE_ALL_CAPS, false ],
541
			[ 'SIMPLE',   Token::WORD, Text_Parser::REQUIRE_ALL_CAPS, true ],
542
			[ 'SIMPLE99', Token::WORD, Text_Parser::REQUIRE_ALL_CAPS, true ],
543
			[ 'simple99', Token::WORD, Text_Parser::ALLOW_ALL_CAPS, true ],
544
			[ 'SIM-PLE',  Token::WORD, Text_Parser::ALLOW_ALL_CAPS, true ],
545
			[ 'sim-ple',  Token::WORD, Text_Parser::NO_ALL_CAPS, true ],
546
			[ 'SIM-PLE',  Token::WORD, Text_Parser::NO_ALL_CAPS, false ],
547
			[ 'sim-ple',  Token::WORD, Text_Parser::REQUIRE_ALL_CAPS, false ],
548
			[ 'SIM-PLE',  Token::WORD, Text_Parser::REQUIRE_ALL_CAPS, true ],
549
		];
550
	}
551
552
	/**
553
	 * Test conforms_to_caps_policy.
554
	 *
555
	 * @covers ::conforms_to_caps_policy
556
	 * @dataProvider provide_conforms_to_caps_policy_data
557
	 *
558
	 * @uses ::load
559
	 * @uses ::is_preceeded_by
560
	 * @uses ::parse_ambiguous_token
561
	 * @uses ::tokenize
562
	 *
563
	 * @param string $value  Token value.
564
	 * @param int    $type   Token type.
565
	 * @param int    $policy All caps policy.
566
	 * @param bool   $result Expected result.
567
	 */
568 View Code Duplication
	public function test_conforms_to_caps_policy( $value, $type, $policy, $result ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
569
		$parser = $this->parser;
570
		$parser->load( $value ); // Ensure that encoding can be determined.
571
572
		$token  = new Token( $value, $type );
573
574
		$this->assertSame( $result, $this->invokeMethod( $parser, 'conforms_to_caps_policy', [ $token, $policy ] ) );
575
	}
576
577
	/**
578
	 * Providate data for testing conforms_to_compounds_policy.
579
	 *
580
	 * @return array
581
	 */
582 View Code Duplication
	public function provide_conforms_to_compounds_policy() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
583
		return [
584
			[ 'simple',   Token::WORD, Text_Parser::ALLOW_COMPOUNDS, true ],
585
			[ 'SIMPLE',   Token::WORD, Text_Parser::ALLOW_COMPOUNDS, true ],
586
			[ 'simple',   Token::WORD, Text_Parser::NO_COMPOUNDS, true ],
587
			[ 'simple99', Token::WORD, Text_Parser::NO_COMPOUNDS, true ],
588
			[ 'simple',   Token::WORD, Text_Parser::REQUIRE_COMPOUNDS, false ],
589
			[ 'SIMPLE',   Token::WORD, Text_Parser::REQUIRE_COMPOUNDS, false ],
590
			[ 'SIMPLE99', Token::WORD, Text_Parser::REQUIRE_COMPOUNDS, false ],
591
			[ 'simple99', Token::WORD, Text_Parser::ALLOW_COMPOUNDS, true ],
592
			[ 'SIM-PLE',  Token::WORD, Text_Parser::ALLOW_COMPOUNDS, true ],
593
			[ 'sim-ple',  Token::WORD, Text_Parser::NO_COMPOUNDS, false ],
594
			[ 'SIM-PLE',  Token::WORD, Text_Parser::NO_COMPOUNDS, false ],
595
			[ 'sim-ple',  Token::WORD, Text_Parser::REQUIRE_COMPOUNDS, true ],
596
			[ 'SIM-PLE',  Token::WORD, Text_Parser::REQUIRE_COMPOUNDS, true ],
597
		];
598
	}
599
600
	/**
601
	 * Test conforms_to_compounds_policy.
602
	 *
603
	 * @covers ::conforms_to_compounds_policy
604
	 * @dataProvider provide_conforms_to_compounds_policy
605
	 *
606
	 * @uses ::load
607
	 * @uses ::is_preceeded_by
608
	 * @uses ::parse_ambiguous_token
609
	 * @uses ::tokenize
610
	 *
611
	 * @param string $value  Token value.
612
	 * @param int    $type   Token type.
613
	 * @param int    $policy Compounds policy.
614
	 * @param bool   $result Expected result.
615
	 */
616 View Code Duplication
	public function test_conforms_to_compounds_policy( $value, $type, $policy, $result ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
617
		$parser = $this->parser;
618
		$parser->load( $value ); // Ensure that encoding can be determined.
619
620
		$token  = new Token( $value, $type );
621
622
		$this->assertSame( $result, $this->invokeMethod( $parser, 'conforms_to_compounds_policy', [ $token, $policy ] ) );
623
	}
624
625
	/**
626
	 * Test get_words.
627
	 *
628
	 * @covers ::get_words
629
	 * @depends test_get_all
630
	 *
631
	 * @uses ::clear
632
	 * @uses ::is_preceeded_by
633
	 * @uses ::load
634
	 * @uses ::parse_ambiguous_token
635
	 * @uses ::tokenize
636
	 * @uses ::unload
637
	 *
638
	 * @param \PHP_Typography\Text_Parser $parser The parser to use.
639
	 */
640
	public function test_get_words_unloaded( Text_Parser $parser ) {
641
		$parser->load( 'A few m1xed W0RDS.' );
642
		$parser->unload();
643
644
		$tokens = $parser->get_words( Text_Parser::REQUIRE_ALL_LETTERS, Text_Parser::NO_ALL_CAPS );
645
		$this->assertCount( 0, $tokens );
646
		$this->assertSame( [], $tokens );
647
648
		return $parser;
649
	}
650
651
	/**
652
	 * Test get_other.
653
	 *
654
	 * @covers ::get_other
655
	 * @depends test_get_all
656
	 *
657
	 * @uses ::get_type
658
	 *
659
	 * @param \PHP_Typography\Text_Parser $parser The parser to use.
660
	 */
661
	public function test_get_other( Text_Parser $parser ) {
662
		$tokens = $parser->get_other();
663
		$this->assertCount( 0, $tokens );
664
665
		return $parser;
666
	}
667
668
	/**
669
	 * Test get_type.
670
	 *
671
	 * @covers ::get_type
672
	 * @depends test_get_all
673
	 *
674
	 * @uses ::get_all
675
	 * @uses ::is_preceeded_by
676
	 * @uses ::load
677
	 * @uses ::parse_ambiguous_token
678
	 * @uses ::tokenize
679
	 *
680
	 * @param \PHP_Typography\Text_Parser $parser The parser to use.
681
	 */
682
	public function test_get_type( Text_Parser $parser ) {
683
		$parser->load( 'A few m1xed W0RDS.' );
684
685
		$words = [];
686
		$tokens = $parser->get_all();
687
		foreach ( $tokens as $index => $token ) {
688
			if ( Token::WORD === $token->type ) {
689
				$words[ $index ] = $token;
690
			}
691
		}
692
693
		$this->assertArraySubset( $words, $parser->get_type( Token::WORD ) );
694
	}
695
}
696