-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathPathTest.php
1059 lines (904 loc) · 47.7 KB
/
PathTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Filesystem\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Path;
/**
* @author Bernhard Schussek <[email protected]>
* @author Thomas Schulz <[email protected]>
* @author Théo Fidry <[email protected]>
*/
class PathTest extends TestCase
{
protected array $storedEnv = [];
protected function setUp(): void
{
$this->storedEnv['HOME'] = getenv('HOME');
$this->storedEnv['HOMEDRIVE'] = getenv('HOMEDRIVE');
$this->storedEnv['HOMEPATH'] = getenv('HOMEPATH');
putenv('HOME=/home/webmozart');
putenv('HOMEDRIVE=');
putenv('HOMEPATH=');
}
protected function tearDown(): void
{
putenv('HOME='.$this->storedEnv['HOME']);
putenv('HOMEDRIVE='.$this->storedEnv['HOMEDRIVE']);
putenv('HOMEPATH='.$this->storedEnv['HOMEPATH']);
}
public static function provideCanonicalizationTests(): \Generator
{
// relative paths (forward slash)
yield ['css/./style.css', 'css/style.css'];
yield ['css/../style.css', 'style.css'];
yield ['css/./../style.css', 'style.css'];
yield ['css/.././style.css', 'style.css'];
yield ['css/../../style.css', '../style.css'];
yield ['./css/style.css', 'css/style.css'];
yield ['../css/style.css', '../css/style.css'];
yield ['./../css/style.css', '../css/style.css'];
yield ['.././css/style.css', '../css/style.css'];
yield ['../../css/style.css', '../../css/style.css'];
yield ['', ''];
yield ['.', ''];
yield ['..', '..'];
yield ['./..', '..'];
yield ['../.', '..'];
yield ['../..', '../..'];
// relative paths (backslash)
yield ['css\\.\\style.css', 'css/style.css'];
yield ['css\\..\\style.css', 'style.css'];
yield ['css\\.\\..\\style.css', 'style.css'];
yield ['css\\..\\.\\style.css', 'style.css'];
yield ['css\\..\\..\\style.css', '../style.css'];
yield ['.\\css\\style.css', 'css/style.css'];
yield ['..\\css\\style.css', '../css/style.css'];
yield ['.\\..\\css\\style.css', '../css/style.css'];
yield ['..\\.\\css\\style.css', '../css/style.css'];
yield ['..\\..\\css\\style.css', '../../css/style.css'];
// absolute paths (forward slash, UNIX)
yield ['/css/style.css', '/css/style.css'];
yield ['/css/./style.css', '/css/style.css'];
yield ['/css/../style.css', '/style.css'];
yield ['/css/./../style.css', '/style.css'];
yield ['/css/.././style.css', '/style.css'];
yield ['/./css/style.css', '/css/style.css'];
yield ['/../css/style.css', '/css/style.css'];
yield ['/./../css/style.css', '/css/style.css'];
yield ['/.././css/style.css', '/css/style.css'];
yield ['/../../css/style.css', '/css/style.css'];
// absolute paths (backslash, UNIX)
yield ['\\css\\style.css', '/css/style.css'];
yield ['\\css\\.\\style.css', '/css/style.css'];
yield ['\\css\\..\\style.css', '/style.css'];
yield ['\\css\\.\\..\\style.css', '/style.css'];
yield ['\\css\\..\\.\\style.css', '/style.css'];
yield ['\\.\\css\\style.css', '/css/style.css'];
yield ['\\..\\css\\style.css', '/css/style.css'];
yield ['\\.\\..\\css\\style.css', '/css/style.css'];
yield ['\\..\\.\\css\\style.css', '/css/style.css'];
yield ['\\..\\..\\css\\style.css', '/css/style.css'];
// absolute paths (forward slash, Windows)
yield ['C:/css/style.css', 'C:/css/style.css'];
yield ['C:/css/./style.css', 'C:/css/style.css'];
yield ['C:/css/../style.css', 'C:/style.css'];
yield ['C:/css/./../style.css', 'C:/style.css'];
yield ['C:/css/.././style.css', 'C:/style.css'];
yield ['C:/./css/style.css', 'C:/css/style.css'];
yield ['C:/../css/style.css', 'C:/css/style.css'];
yield ['C:/./../css/style.css', 'C:/css/style.css'];
yield ['C:/.././css/style.css', 'C:/css/style.css'];
yield ['C:/../../css/style.css', 'C:/css/style.css'];
// absolute paths (backslash, Windows)
yield ['C:\\css\\style.css', 'C:/css/style.css'];
yield ['C:\\css\\.\\style.css', 'C:/css/style.css'];
yield ['C:\\css\\..\\style.css', 'C:/style.css'];
yield ['C:\\css\\.\\..\\style.css', 'C:/style.css'];
yield ['C:\\css\\..\\.\\style.css', 'C:/style.css'];
yield ['C:\\.\\css\\style.css', 'C:/css/style.css'];
yield ['C:\\..\\css\\style.css', 'C:/css/style.css'];
yield ['C:\\.\\..\\css\\style.css', 'C:/css/style.css'];
yield ['C:\\..\\.\\css\\style.css', 'C:/css/style.css'];
yield ['C:\\..\\..\\css\\style.css', 'C:/css/style.css'];
// Windows special case
yield ['C:', 'C:/'];
// Don't change malformed path
yield ['C:css/style.css', 'C:css/style.css'];
// absolute paths (stream, UNIX)
yield ['phar:///css/style.css', 'phar:///css/style.css'];
yield ['phar:///css/./style.css', 'phar:///css/style.css'];
yield ['phar:///css/../style.css', 'phar:///style.css'];
yield ['phar:///css/./../style.css', 'phar:///style.css'];
yield ['phar:///css/.././style.css', 'phar:///style.css'];
yield ['phar:///./css/style.css', 'phar:///css/style.css'];
yield ['phar:///../css/style.css', 'phar:///css/style.css'];
yield ['phar:///./../css/style.css', 'phar:///css/style.css'];
yield ['phar:///.././css/style.css', 'phar:///css/style.css'];
yield ['phar:///../../css/style.css', 'phar:///css/style.css'];
// absolute paths (stream, Windows)
yield ['phar://C:/css/style.css', 'phar://C:/css/style.css'];
yield ['phar://C:/css/./style.css', 'phar://C:/css/style.css'];
yield ['phar://C:/css/../style.css', 'phar://C:/style.css'];
yield ['phar://C:/css/./../style.css', 'phar://C:/style.css'];
yield ['phar://C:/css/.././style.css', 'phar://C:/style.css'];
yield ['phar://C:/./css/style.css', 'phar://C:/css/style.css'];
yield ['phar://C:/../css/style.css', 'phar://C:/css/style.css'];
yield ['phar://C:/./../css/style.css', 'phar://C:/css/style.css'];
yield ['phar://C:/.././css/style.css', 'phar://C:/css/style.css'];
yield ['phar://C:/../../css/style.css', 'phar://C:/css/style.css'];
// paths with "~" UNIX
yield ['~/css/style.css', '/home/webmozart/css/style.css'];
yield ['~/css/./style.css', '/home/webmozart/css/style.css'];
yield ['~/css/../style.css', '/home/webmozart/style.css'];
yield ['~/css/./../style.css', '/home/webmozart/style.css'];
yield ['~/css/.././style.css', '/home/webmozart/style.css'];
yield ['~/./css/style.css', '/home/webmozart/css/style.css'];
yield ['~/../css/style.css', '/home/css/style.css'];
yield ['~/./../css/style.css', '/home/css/style.css'];
yield ['~/.././css/style.css', '/home/css/style.css'];
yield ['~/../../css/style.css', '/css/style.css'];
}
/**
* @dataProvider provideCanonicalizationTests
*/
public function testCanonicalize(string $path, string $canonicalized)
{
$this->assertSame($canonicalized, Path::canonicalize($path));
}
public static function provideGetDirectoryTests(): \Generator
{
yield ['/webmozart/symfony/style.css', '/webmozart/symfony'];
yield ['/webmozart/symfony', '/webmozart'];
yield ['/webmozart', '/'];
yield ['/', '/'];
yield ['', ''];
yield ['\\webmozart\\symfony\\style.css', '/webmozart/symfony'];
yield ['\\webmozart\\symfony', '/webmozart'];
yield ['\\webmozart', '/'];
yield ['\\', '/'];
yield ['C:/webmozart/symfony/style.css', 'C:/webmozart/symfony'];
yield ['C:/webmozart/symfony', 'C:/webmozart'];
yield ['C:/webmozart', 'C:/'];
yield ['C:/', 'C:/'];
yield ['C:', 'C:/'];
yield ['C:\\webmozart\\symfony\\style.css', 'C:/webmozart/symfony'];
yield ['C:\\webmozart\\symfony', 'C:/webmozart'];
yield ['C:\\webmozart', 'C:/'];
yield ['C:\\', 'C:/'];
yield ['phar:///webmozart/symfony/style.css', 'phar:///webmozart/symfony'];
yield ['phar:///webmozart/symfony', 'phar:///webmozart'];
yield ['phar:///webmozart', 'phar:///'];
yield ['phar:///', 'phar:///'];
yield ['phar://C:/webmozart/symfony/style.css', 'phar://C:/webmozart/symfony'];
yield ['phar://C:/webmozart/symfony', 'phar://C:/webmozart'];
yield ['phar://C:/webmozart', 'phar://C:/'];
yield ['phar://C:/', 'phar://C:/'];
yield ['webmozart/symfony/style.css', 'webmozart/symfony'];
yield ['webmozart/symfony', 'webmozart'];
yield ['webmozart', ''];
yield ['webmozart\\symfony\\style.css', 'webmozart/symfony'];
yield ['webmozart\\symfony', 'webmozart'];
yield ['webmozart', ''];
yield ['/webmozart/./symfony/style.css', '/webmozart/symfony'];
yield ['/webmozart/../symfony/style.css', '/symfony'];
yield ['/webmozart/./../symfony/style.css', '/symfony'];
yield ['/webmozart/.././symfony/style.css', '/symfony'];
yield ['/webmozart/../../symfony/style.css', '/symfony'];
yield ['/.', '/'];
yield ['/..', '/'];
yield ['C:webmozart', ''];
yield ['D:/Folder/Aééé/Subfolder', 'D:/Folder/Aééé'];
}
/**
* @dataProvider provideGetDirectoryTests
*/
public function testGetDirectory(string $path, string $directory)
{
$this->assertSame($directory, Path::getDirectory($path));
}
public static function provideGetFilenameWithoutExtensionTests(): \Generator
{
yield ['/webmozart/symfony/style.css.twig', null, 'style.css'];
yield ['/webmozart/symfony/style.css.', null, 'style.css'];
yield ['/webmozart/symfony/style.css', null, 'style'];
yield ['/webmozart/symfony/.style.css', null, '.style'];
yield ['/webmozart/symfony/', null, 'symfony'];
yield ['/webmozart/symfony', null, 'symfony'];
yield ['/', null, ''];
yield ['', null, ''];
yield ['/webmozart/symfony/style.css', 'css', 'style'];
yield ['/webmozart/symfony/style.css', '.css', 'style'];
yield ['/webmozart/symfony/style.css', 'twig', 'style.css'];
yield ['/webmozart/symfony/style.css', '.twig', 'style.css'];
yield ['/webmozart/symfony/style.css', '', 'style.css'];
yield ['/webmozart/symfony/style.css.', '', 'style.css'];
yield ['/webmozart/symfony/style.css.', '.', 'style.css'];
yield ['/webmozart/symfony/style.css.', '.css', 'style.css'];
yield ['/webmozart/symfony/.style.css', 'css', '.style'];
yield ['/webmozart/symfony/.style.css', '.css', '.style'];
}
/**
* @dataProvider provideGetFilenameWithoutExtensionTests
*/
public function testGetFilenameWithoutExtension(string $path, ?string $extension, string $filename)
{
$this->assertSame($filename, Path::getFilenameWithoutExtension($path, $extension));
}
public static function provideGetExtensionTests(): \Generator
{
yield ['/webmozart/symfony/style.css.twig', false, 'twig'];
yield ['/webmozart/symfony/style.css', false, 'css'];
yield ['/webmozart/symfony/style.css.', false, ''];
yield ['/webmozart/symfony/', false, ''];
yield ['/webmozart/symfony', false, ''];
yield ['/', false, ''];
yield ['', false, ''];
yield ['/webmozart/symfony/style.CSS', false, 'CSS'];
yield ['/webmozart/symfony/style.CSS', true, 'css'];
yield ['/webmozart/symfony/style.ÄÖÜ', false, 'ÄÖÜ'];
yield ['/webmozart/symfony/style.ÄÖÜ', true, 'äöü'];
}
/**
* @dataProvider provideGetExtensionTests
*/
public function testGetExtension(string $path, bool $forceLowerCase, string $extension)
{
$this->assertSame($extension, Path::getExtension($path, $forceLowerCase));
}
public static function provideHasExtensionTests(): \Generator
{
yield [true, '/webmozart/symfony/style.css.twig', null, false];
yield [true, '/webmozart/symfony/style.css', null, false];
yield [false, '/webmozart/symfony/style.css.', null, false];
yield [false, '/webmozart/symfony/', null, false];
yield [false, '/webmozart/symfony', null, false];
yield [false, '/', null, false];
yield [false, '', null, false];
yield [true, '/webmozart/symfony/style.css.twig', 'twig', false];
yield [false, '/webmozart/symfony/style.css.twig', 'css', false];
yield [true, '/webmozart/symfony/style.css', 'css', false];
yield [true, '/webmozart/symfony/style.css', '.css', false];
yield [true, '/webmozart/symfony/style.css.', '', false];
yield [false, '/webmozart/symfony/', 'ext', false];
yield [false, '/webmozart/symfony', 'ext', false];
yield [false, '/', 'ext', false];
yield [false, '', 'ext', false];
yield [false, '/webmozart/symfony/style.css', 'CSS', false];
yield [true, '/webmozart/symfony/style.css', 'CSS', true];
yield [false, '/webmozart/symfony/style.CSS', 'css', false];
yield [true, '/webmozart/symfony/style.CSS', 'css', true];
yield [true, '/webmozart/symfony/style.ÄÖÜ', 'ÄÖÜ', false];
yield [true, '/webmozart/symfony/style.css', ['ext', 'css'], false];
yield [true, '/webmozart/symfony/style.css', ['.ext', '.css'], false];
yield [true, '/webmozart/symfony/style.css.', ['ext', ''], false];
yield [false, '/webmozart/symfony/style.css', ['foo', 'bar', ''], false];
yield [false, '/webmozart/symfony/style.css', ['.foo', '.bar', ''], false];
// This can only be tested, when mbstring is installed
yield [true, '/webmozart/symfony/style.ÄÖÜ', 'äöü', true];
yield [true, '/webmozart/symfony/style.ÄÖÜ', ['äöü'], true];
}
/**
* @dataProvider provideHasExtensionTests
*
* @param string|string[]|null $extension
*/
public function testHasExtension(bool $hasExtension, string $path, $extension, bool $ignoreCase)
{
$this->assertSame($hasExtension, Path::hasExtension($path, $extension, $ignoreCase));
}
public static function provideChangeExtensionTests(): \Generator
{
yield ['/webmozart/symfony/style.css.twig', 'html', '/webmozart/symfony/style.css.html'];
yield ['/webmozart/symfony/style.css', 'sass', '/webmozart/symfony/style.sass'];
yield ['/webmozart/symfony/style.css', '.sass', '/webmozart/symfony/style.sass'];
yield ['/webmozart/symfony/style.css', '', '/webmozart/symfony/style.'];
yield ['/webmozart/symfony/style.css.', 'twig', '/webmozart/symfony/style.css.twig'];
yield ['/webmozart/symfony/style.css.', '', '/webmozart/symfony/style.css.'];
yield ['/webmozart/symfony/style.css', 'äöü', '/webmozart/symfony/style.äöü'];
yield ['/webmozart/symfony/style.äöü', 'css', '/webmozart/symfony/style.css'];
yield ['/webmozart/symfony/', 'css', '/webmozart/symfony/'];
yield ['/webmozart/symfony', 'css', '/webmozart/symfony.css'];
yield ['/', 'css', '/'];
yield ['', 'css', ''];
}
/**
* @dataProvider provideChangeExtensionTests
*/
public function testChangeExtension(string $path, string $extension, string $pathExpected)
{
$this->assertSame($pathExpected, Path::changeExtension($path, $extension));
}
public static function provideIsAbsolutePathTests(): \Generator
{
yield ['/css/style.css', true];
yield ['/', true];
yield ['css/style.css', false];
yield ['', false];
yield ['\\css\\style.css', true];
yield ['\\', true];
yield ['css\\style.css', false];
yield ['C:/css/style.css', true];
yield ['D:/', true];
yield ['C:///windows', true];
yield ['C://test', true];
yield ['E:\\css\\style.css', true];
yield ['F:\\', true];
yield ['phar:///css/style.css', true];
yield ['phar:///', true];
// Windows special case
yield ['C:', true];
// Not considered absolute
yield ['C:css/style.css', false];
}
/**
* @dataProvider provideIsAbsolutePathTests
*/
public function testIsAbsolute(string $path, bool $isAbsolute)
{
$this->assertSame($isAbsolute, Path::isAbsolute($path));
}
/**
* @dataProvider provideIsAbsolutePathTests
*/
public function testIsRelative(string $path, bool $isAbsolute)
{
$this->assertSame(!$isAbsolute, Path::isRelative($path));
}
public static function provideGetRootTests(): \Generator
{
yield ['/css/style.css', '/'];
yield ['/', '/'];
yield ['css/style.css', ''];
yield ['', ''];
yield ['\\css\\style.css', '/'];
yield ['\\', '/'];
yield ['css\\style.css', ''];
yield ['C:/css/style.css', 'C:/'];
yield ['C:/', 'C:/'];
yield ['C:', 'C:/'];
yield ['D:\\css\\style.css', 'D:/'];
yield ['D:\\', 'D:/'];
yield ['phar:///css/style.css', 'phar:///'];
yield ['phar:///', 'phar:///'];
yield ['phar://C:/css/style.css', 'phar://C:/'];
yield ['phar://C:/', 'phar://C:/'];
yield ['phar://C:', 'phar://C:/'];
}
/**
* @dataProvider provideGetRootTests
*/
public function testGetRoot(string $path, string $root)
{
$this->assertSame($root, Path::getRoot($path));
}
private static function getPathTests(): \Generator
{
yield from [
// relative to absolute path
['css/style.css', '/webmozart/symfony', '/webmozart/symfony/css/style.css'],
['../css/style.css', '/webmozart/symfony', '/webmozart/css/style.css'],
['../../css/style.css', '/webmozart/symfony', '/css/style.css'],
// relative to root
['css/style.css', '/', '/css/style.css'],
['css/style.css', 'C:', 'C:/css/style.css'],
['css/style.css', 'C:/', 'C:/css/style.css'],
// same sub directories in different base directories
['../../symfony/css/style.css', '/webmozart/css', '/symfony/css/style.css'],
['', '/webmozart/symfony', '/webmozart/symfony'],
['..', '/webmozart/symfony', '/webmozart'],
];
}
public static function provideMakeAbsoluteTests(): \Generator
{
yield from self::getPathTests();
// collapse dots
yield ['css/./style.css', '/webmozart/symfony', '/webmozart/symfony/css/style.css'];
yield ['css/../style.css', '/webmozart/symfony', '/webmozart/symfony/style.css'];
yield ['css/./../style.css', '/webmozart/symfony', '/webmozart/symfony/style.css'];
yield ['css/.././style.css', '/webmozart/symfony', '/webmozart/symfony/style.css'];
yield ['./css/style.css', '/webmozart/symfony', '/webmozart/symfony/css/style.css'];
yield ['css\\.\\style.css', '\\webmozart\\symfony', '/webmozart/symfony/css/style.css'];
yield ['css\\..\\style.css', '\\webmozart\\symfony', '/webmozart/symfony/style.css'];
yield ['css\\.\\..\\style.css', '\\webmozart\\symfony', '/webmozart/symfony/style.css'];
yield ['css\\..\\.\\style.css', '\\webmozart\\symfony', '/webmozart/symfony/style.css'];
yield ['.\\css\\style.css', '\\webmozart\\symfony', '/webmozart/symfony/css/style.css'];
// collapse dots on root
yield ['./css/style.css', '/', '/css/style.css'];
yield ['../css/style.css', '/', '/css/style.css'];
yield ['../css/./style.css', '/', '/css/style.css'];
yield ['../css/../style.css', '/', '/style.css'];
yield ['../css/./../style.css', '/', '/style.css'];
yield ['../css/.././style.css', '/', '/style.css'];
yield ['.\\css\\style.css', '\\', '/css/style.css'];
yield ['..\\css\\style.css', '\\', '/css/style.css'];
yield ['..\\css\\.\\style.css', '\\', '/css/style.css'];
yield ['..\\css\\..\\style.css', '\\', '/style.css'];
yield ['..\\css\\.\\..\\style.css', '\\', '/style.css'];
yield ['..\\css\\..\\.\\style.css', '\\', '/style.css'];
yield ['./css/style.css', 'C:/', 'C:/css/style.css'];
yield ['../css/style.css', 'C:/', 'C:/css/style.css'];
yield ['../css/./style.css', 'C:/', 'C:/css/style.css'];
yield ['../css/../style.css', 'C:/', 'C:/style.css'];
yield ['../css/./../style.css', 'C:/', 'C:/style.css'];
yield ['../css/.././style.css', 'C:/', 'C:/style.css'];
yield ['.\\css\\style.css', 'C:\\', 'C:/css/style.css'];
yield ['..\\css\\style.css', 'C:\\', 'C:/css/style.css'];
yield ['..\\css\\.\\style.css', 'C:\\', 'C:/css/style.css'];
yield ['..\\css\\..\\style.css', 'C:\\', 'C:/style.css'];
yield ['..\\css\\.\\..\\style.css', 'C:\\', 'C:/style.css'];
yield ['..\\css\\..\\.\\style.css', 'C:\\', 'C:/style.css'];
yield ['./css/style.css', 'phar:///', 'phar:///css/style.css'];
yield ['../css/style.css', 'phar:///', 'phar:///css/style.css'];
yield ['../css/./style.css', 'phar:///', 'phar:///css/style.css'];
yield ['../css/../style.css', 'phar:///', 'phar:///style.css'];
yield ['../css/./../style.css', 'phar:///', 'phar:///style.css'];
yield ['../css/.././style.css', 'phar:///', 'phar:///style.css'];
yield ['./css/style.css', 'phar://C:/', 'phar://C:/css/style.css'];
yield ['../css/style.css', 'phar://C:/', 'phar://C:/css/style.css'];
yield ['../css/./style.css', 'phar://C:/', 'phar://C:/css/style.css'];
yield ['../css/../style.css', 'phar://C:/', 'phar://C:/style.css'];
yield ['../css/./../style.css', 'phar://C:/', 'phar://C:/style.css'];
yield ['../css/.././style.css', 'phar://C:/', 'phar://C:/style.css'];
// absolute paths
yield ['/css/style.css', '/webmozart/symfony', '/css/style.css'];
yield ['\\css\\style.css', '/webmozart/symfony', '/css/style.css'];
yield ['C:/css/style.css', 'C:/webmozart/symfony', 'C:/css/style.css'];
yield ['D:\\css\\style.css', 'D:/webmozart/symfony', 'D:/css/style.css'];
}
/**
* @dataProvider provideMakeAbsoluteTests
*/
public function testMakeAbsolute(string $relativePath, string $basePath, string $absolutePath)
{
$this->assertSame($absolutePath, Path::makeAbsolute($relativePath, $basePath));
}
public function testMakeAbsoluteFailsIfBasePathNotAbsolute()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The base path "webmozart/symfony" is not an absolute path.');
Path::makeAbsolute('css/style.css', 'webmozart/symfony');
}
public function testMakeAbsoluteFailsIfBasePathEmpty()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The base path must be a non-empty string. Got: ""');
Path::makeAbsolute('css/style.css', '');
}
public static function provideAbsolutePathsWithDifferentRoots(): \Generator
{
yield ['C:/css/style.css', '/webmozart/symfony'];
yield ['C:/css/style.css', '\\webmozart\\symfony'];
yield ['C:\\css\\style.css', '/webmozart/symfony'];
yield ['C:\\css\\style.css', '\\webmozart\\symfony'];
yield ['/css/style.css', 'C:/webmozart/symfony'];
yield ['/css/style.css', 'C:\\webmozart\\symfony'];
yield ['\\css\\style.css', 'C:/webmozart/symfony'];
yield ['\\css\\style.css', 'C:\\webmozart\\symfony'];
yield ['D:/css/style.css', 'C:/webmozart/symfony'];
yield ['D:/css/style.css', 'C:\\webmozart\\symfony'];
yield ['D:\\css\\style.css', 'C:/webmozart/symfony'];
yield ['D:\\css\\style.css', 'C:\\webmozart\\symfony'];
yield ['phar:///css/style.css', '/webmozart/symfony'];
yield ['/css/style.css', 'phar:///webmozart/symfony'];
yield ['phar://C:/css/style.css', 'C:/webmozart/symfony'];
yield ['phar://C:/css/style.css', 'C:\\webmozart\\symfony'];
yield ['phar://C:\\css\\style.css', 'C:/webmozart/symfony'];
yield ['phar://C:\\css\\style.css', 'C:\\webmozart\\symfony'];
}
/**
* @dataProvider provideAbsolutePathsWithDifferentRoots
*/
public function testMakeAbsoluteDoesNotFailIfDifferentRoot(string $basePath, string $absolutePath)
{
// If a path in partition D: is passed, but $basePath is in partition
// C:, the path should be returned unchanged
$this->assertSame(Path::canonicalize($absolutePath), Path::makeAbsolute($absolutePath, $basePath));
}
public static function provideMakeRelativeTests(): \Generator
{
foreach (self::getPathTests() as $set) {
yield [$set[2], $set[1], $set[0]];
}
yield ['/webmozart/symfony/./css/style.css', '/webmozart/symfony', 'css/style.css'];
yield ['/webmozart/symfony/../css/style.css', '/webmozart/symfony', '../css/style.css'];
yield ['/webmozart/symfony/.././css/style.css', '/webmozart/symfony', '../css/style.css'];
yield ['/webmozart/symfony/./../css/style.css', '/webmozart/symfony', '../css/style.css'];
yield ['/webmozart/symfony/../../css/style.css', '/webmozart/symfony', '../../css/style.css'];
yield ['/webmozart/symfony/css/style.css', '/webmozart/./symfony', 'css/style.css'];
yield ['/webmozart/symfony/css/style.css', '/webmozart/../symfony', '../webmozart/symfony/css/style.css'];
yield ['/webmozart/symfony/css/style.css', '/webmozart/./../symfony', '../webmozart/symfony/css/style.css'];
yield ['/webmozart/symfony/css/style.css', '/webmozart/.././symfony', '../webmozart/symfony/css/style.css'];
yield ['/webmozart/symfony/css/style.css', '/webmozart/../../symfony', '../webmozart/symfony/css/style.css'];
// first argument shorter than second
yield ['/css', '/webmozart/symfony', '../../css'];
// second argument shorter than first
yield ['/webmozart/symfony', '/css', '../webmozart/symfony'];
yield ['\\webmozart\\symfony\\css\\style.css', '\\webmozart\\symfony', 'css/style.css'];
yield ['\\webmozart\\css\\style.css', '\\webmozart\\symfony', '../css/style.css'];
yield ['\\css\\style.css', '\\webmozart\\symfony', '../../css/style.css'];
yield ['C:/webmozart/symfony/css/style.css', 'C:/webmozart/symfony', 'css/style.css'];
yield ['C:/webmozart/css/style.css', 'C:/webmozart/symfony', '../css/style.css'];
yield ['C:/css/style.css', 'C:/webmozart/symfony', '../../css/style.css'];
yield ['C:\\webmozart\\symfony\\css\\style.css', 'C:\\webmozart\\symfony', 'css/style.css'];
yield ['C:\\webmozart\\css\\style.css', 'C:\\webmozart\\symfony', '../css/style.css'];
yield ['C:\\css\\style.css', 'C:\\webmozart\\symfony', '../../css/style.css'];
yield ['phar:///webmozart/symfony/css/style.css', 'phar:///webmozart/symfony', 'css/style.css'];
yield ['phar:///webmozart/css/style.css', 'phar:///webmozart/symfony', '../css/style.css'];
yield ['phar:///css/style.css', 'phar:///webmozart/symfony', '../../css/style.css'];
yield ['phar://C:/webmozart/symfony/css/style.css', 'phar://C:/webmozart/symfony', 'css/style.css'];
yield ['phar://C:/webmozart/css/style.css', 'phar://C:/webmozart/symfony', '../css/style.css'];
yield ['phar://C:/css/style.css', 'phar://C:/webmozart/symfony', '../../css/style.css'];
// already relative + already in root basepath
yield ['../style.css', '/', 'style.css'];
yield ['./style.css', '/', 'style.css'];
yield ['../../style.css', '/', 'style.css'];
yield ['..\\style.css', 'C:\\', 'style.css'];
yield ['.\\style.css', 'C:\\', 'style.css'];
yield ['..\\..\\style.css', 'C:\\', 'style.css'];
yield ['../style.css', 'C:/', 'style.css'];
yield ['./style.css', 'C:/', 'style.css'];
yield ['../../style.css', 'C:/', 'style.css'];
yield ['..\\style.css', '\\', 'style.css'];
yield ['.\\style.css', '\\', 'style.css'];
yield ['..\\..\\style.css', '\\', 'style.css'];
yield ['../style.css', 'phar:///', 'style.css'];
yield ['./style.css', 'phar:///', 'style.css'];
yield ['../../style.css', 'phar:///', 'style.css'];
yield ['..\\style.css', 'phar://C:\\', 'style.css'];
yield ['.\\style.css', 'phar://C:\\', 'style.css'];
yield ['..\\..\\style.css', 'phar://C:\\', 'style.css'];
yield ['css/../style.css', '/', 'style.css'];
yield ['css/./style.css', '/', 'css/style.css'];
yield ['css\\..\\style.css', 'C:\\', 'style.css'];
yield ['css\\.\\style.css', 'C:\\', 'css/style.css'];
yield ['css/../style.css', 'C:/', 'style.css'];
yield ['css/./style.css', 'C:/', 'css/style.css'];
yield ['css\\..\\style.css', '\\', 'style.css'];
yield ['css\\.\\style.css', '\\', 'css/style.css'];
yield ['css/../style.css', 'phar:///', 'style.css'];
yield ['css/./style.css', 'phar:///', 'css/style.css'];
yield ['css\\..\\style.css', 'phar://C:\\', 'style.css'];
yield ['css\\.\\style.css', 'phar://C:\\', 'css/style.css'];
// already relative
yield ['css/style.css', '/webmozart/symfony', 'css/style.css'];
yield ['css\\style.css', '\\webmozart\\symfony', 'css/style.css'];
// both relative
yield ['css/style.css', 'webmozart/symfony', '../../css/style.css'];
yield ['css\\style.css', 'webmozart\\symfony', '../../css/style.css'];
// relative to empty
yield ['css/style.css', '', 'css/style.css'];
yield ['css\\style.css', '', 'css/style.css'];
// different slashes in path and base path
yield ['/webmozart/symfony/css/style.css', '\\webmozart\\symfony', 'css/style.css'];
yield ['\\webmozart\\symfony\\css\\style.css', '/webmozart/symfony', 'css/style.css'];
}
/**
* @dataProvider provideMakeRelativeTests
*/
public function testMakeRelative(string $absolutePath, string $basePath, string $relativePath)
{
$this->assertSame($relativePath, Path::makeRelative($absolutePath, $basePath));
}
public function testMakeRelativeFailsIfAbsolutePathAndBasePathNotAbsolute()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The absolute path "/webmozart/symfony/css/style.css" cannot be made relative to the relative path "webmozart/symfony". You should provide an absolute base path instead.');
Path::makeRelative('/webmozart/symfony/css/style.css', 'webmozart/symfony');
}
public function testMakeRelativeFailsIfAbsolutePathAndBasePathEmpty()
{
$this->expectExceptionMessage('The absolute path "/webmozart/symfony/css/style.css" cannot be made relative to the relative path "". You should provide an absolute base path instead.');
Path::makeRelative('/webmozart/symfony/css/style.css', '');
}
/**
* @dataProvider provideAbsolutePathsWithDifferentRoots
*/
public function testMakeRelativeFailsIfDifferentRoot(string $absolutePath, string $basePath)
{
$this->expectException(\InvalidArgumentException::class);
Path::makeRelative($absolutePath, $basePath);
}
public static function provideIsLocalTests(): \Generator
{
yield ['/bg.png', true];
yield ['bg.png', true];
yield ['http://example.com/bg.png', false];
yield ['http://example.com', false];
yield ['', false];
}
/**
* @dataProvider provideIsLocalTests
*/
public function testIsLocal(string $path, bool $isLocal)
{
$this->assertSame($isLocal, Path::isLocal($path));
}
public static function provideGetLongestCommonBasePathTests(): \Generator
{
// same paths
yield [['/base/path', '/base/path'], '/base/path'];
yield [['C:/base/path', 'C:/base/path'], 'C:/base/path'];
yield [['C:\\base\\path', 'C:\\base\\path'], 'C:/base/path'];
yield [['C:/base/path', 'C:\\base\\path'], 'C:/base/path'];
yield [['phar:///base/path', 'phar:///base/path'], 'phar:///base/path'];
yield [['phar://C:/base/path', 'phar://C:/base/path'], 'phar://C:/base/path'];
// trailing slash
yield [['/base/path/', '/base/path'], '/base/path'];
yield [['C:/base/path/', 'C:/base/path'], 'C:/base/path'];
yield [['C:\\base\\path\\', 'C:\\base\\path'], 'C:/base/path'];
yield [['C:/base/path/', 'C:\\base\\path'], 'C:/base/path'];
yield [['phar:///base/path/', 'phar:///base/path'], 'phar:///base/path'];
yield [['phar://C:/base/path/', 'phar://C:/base/path'], 'phar://C:/base/path'];
yield [['/base/path', '/base/path/'], '/base/path'];
yield [['C:/base/path', 'C:/base/path/'], 'C:/base/path'];
yield [['C:\\base\\path', 'C:\\base\\path\\'], 'C:/base/path'];
yield [['C:/base/path', 'C:\\base\\path\\'], 'C:/base/path'];
yield [['phar:///base/path', 'phar:///base/path/'], 'phar:///base/path'];
yield [['phar://C:/base/path', 'phar://C:/base/path/'], 'phar://C:/base/path'];
// first in second
yield [['/base/path/sub', '/base/path'], '/base/path'];
yield [['C:/base/path/sub', 'C:/base/path'], 'C:/base/path'];
yield [['C:\\base\\path\\sub', 'C:\\base\\path'], 'C:/base/path'];
yield [['C:/base/path/sub', 'C:\\base\\path'], 'C:/base/path'];
yield [['phar:///base/path/sub', 'phar:///base/path'], 'phar:///base/path'];
yield [['phar://C:/base/path/sub', 'phar://C:/base/path'], 'phar://C:/base/path'];
// second in first
yield [['/base/path', '/base/path/sub'], '/base/path'];
yield [['C:/base/path', 'C:/base/path/sub'], 'C:/base/path'];
yield [['C:\\base\\path', 'C:\\base\\path\\sub'], 'C:/base/path'];
yield [['C:/base/path', 'C:\\base\\path\\sub'], 'C:/base/path'];
yield [['phar:///base/path', 'phar:///base/path/sub'], 'phar:///base/path'];
yield [['phar://C:/base/path', 'phar://C:/base/path/sub'], 'phar://C:/base/path'];
// first is prefix
yield [['/base/path/di', '/base/path/dir'], '/base/path'];
yield [['C:/base/path/di', 'C:/base/path/dir'], 'C:/base/path'];
yield [['C:\\base\\path\\di', 'C:\\base\\path\\dir'], 'C:/base/path'];
yield [['C:/base/path/di', 'C:\\base\\path\\dir'], 'C:/base/path'];
yield [['phar:///base/path/di', 'phar:///base/path/dir'], 'phar:///base/path'];
yield [['phar://C:/base/path/di', 'phar://C:/base/path/dir'], 'phar://C:/base/path'];
// second is prefix
yield [['/base/path/dir', '/base/path/di'], '/base/path'];
yield [['C:/base/path/dir', 'C:/base/path/di'], 'C:/base/path'];
yield [['C:\\base\\path\\dir', 'C:\\base\\path\\di'], 'C:/base/path'];
yield [['C:/base/path/dir', 'C:\\base\\path\\di'], 'C:/base/path'];
yield [['phar:///base/path/dir', 'phar:///base/path/di'], 'phar:///base/path'];
yield [['phar://C:/base/path/dir', 'phar://C:/base/path/di'], 'phar://C:/base/path'];
// root is common base path
yield [['/first', '/second'], '/'];
yield [['C:/first', 'C:/second'], 'C:/'];
yield [['C:\\first', 'C:\\second'], 'C:/'];
yield [['C:/first', 'C:\\second'], 'C:/'];
yield [['phar:///first', 'phar:///second'], 'phar:///'];
yield [['phar://C:/first', 'phar://C:/second'], 'phar://C:/'];
// windows vs unix
yield [['/base/path', 'C:/base/path'], null];
yield [['C:/base/path', '/base/path'], null];
yield [['/base/path', 'C:\\base\\path'], null];
yield [['phar:///base/path', 'phar://C:/base/path'], null];
// different partitions
yield [['C:/base/path', 'D:/base/path'], null];
yield [['C:/base/path', 'D:\\base\\path'], null];
yield [['C:\\base\\path', 'D:\\base\\path'], null];
yield [['phar://C:/base/path', 'phar://D:/base/path'], null];
// three paths
yield [['/base/path/foo', '/base/path', '/base/path/bar'], '/base/path'];
yield [['C:/base/path/foo', 'C:/base/path', 'C:/base/path/bar'], 'C:/base/path'];
yield [['C:\\base\\path\\foo', 'C:\\base\\path', 'C:\\base\\path\\bar'], 'C:/base/path'];
yield [['C:/base/path//foo', 'C:/base/path', 'C:\\base\\path\\bar'], 'C:/base/path'];
yield [['phar:///base/path/foo', 'phar:///base/path', 'phar:///base/path/bar'], 'phar:///base/path'];
yield [['phar://C:/base/path/foo', 'phar://C:/base/path', 'phar://C:/base/path/bar'], 'phar://C:/base/path'];
// three paths with root
yield [['/base/path/foo', '/', '/base/path/bar'], '/'];
yield [['C:/base/path/foo', 'C:/', 'C:/base/path/bar'], 'C:/'];
yield [['C:\\base\\path\\foo', 'C:\\', 'C:\\base\\path\\bar'], 'C:/'];
yield [['C:/base/path//foo', 'C:/', 'C:\\base\\path\\bar'], 'C:/'];
yield [['phar:///base/path/foo', 'phar:///', 'phar:///base/path/bar'], 'phar:///'];
yield [['phar://C:/base/path/foo', 'phar://C:/', 'phar://C:/base/path/bar'], 'phar://C:/'];
// three paths, different roots
yield [['/base/path/foo', 'C:/base/path', '/base/path/bar'], null];
yield [['/base/path/foo', 'C:\\base\\path', '/base/path/bar'], null];
yield [['C:/base/path/foo', 'D:/base/path', 'C:/base/path/bar'], null];
yield [['C:\\base\\path\\foo', 'D:\\base\\path', 'C:\\base\\path\\bar'], null];
yield [['C:/base/path//foo', 'D:/base/path', 'C:\\base\\path\\bar'], null];
yield [['phar:///base/path/foo', 'phar://C:/base/path', 'phar:///base/path/bar'], null];
yield [['phar://C:/base/path/foo', 'phar://D:/base/path', 'phar://C:/base/path/bar'], null];
// only one path
yield [['/base/path'], '/base/path'];
yield [['C:/base/path'], 'C:/base/path'];
yield [['C:\\base\\path'], 'C:/base/path'];
yield [['phar:///base/path'], 'phar:///base/path'];
yield [['phar://C:/base/path'], 'phar://C:/base/path'];
}
/**
* @dataProvider provideGetLongestCommonBasePathTests
*
* @param string[] $paths
*/
public function testGetLongestCommonBasePath(array $paths, ?string $basePath)
{
$this->assertSame($basePath, Path::getLongestCommonBasePath(...$paths));
}
public static function provideIsBasePathTests(): \Generator
{
// same paths
yield ['/base/path', '/base/path', true];
yield ['C:/base/path', 'C:/base/path', true];
yield ['C:\\base\\path', 'C:\\base\\path', true];
yield ['C:/base/path', 'C:\\base\\path', true];
yield ['phar:///base/path', 'phar:///base/path', true];
yield ['phar://C:/base/path', 'phar://C:/base/path', true];
// trailing slash
yield ['/base/path/', '/base/path', true];
yield ['C:/base/path/', 'C:/base/path', true];
yield ['C:\\base\\path\\', 'C:\\base\\path', true];
yield ['C:/base/path/', 'C:\\base\\path', true];
yield ['phar:///base/path/', 'phar:///base/path', true];
yield ['phar://C:/base/path/', 'phar://C:/base/path', true];
yield ['/base/path', '/base/path/', true];
yield ['C:/base/path', 'C:/base/path/', true];
yield ['C:\\base\\path', 'C:\\base\\path\\', true];
yield ['C:/base/path', 'C:\\base\\path\\', true];
yield ['phar:///base/path', 'phar:///base/path/', true];
yield ['phar://C:/base/path', 'phar://C:/base/path/', true];
// first in second
yield ['/base/path/sub', '/base/path', false];
yield ['C:/base/path/sub', 'C:/base/path', false];
yield ['C:\\base\\path\\sub', 'C:\\base\\path', false];
yield ['C:/base/path/sub', 'C:\\base\\path', false];
yield ['phar:///base/path/sub', 'phar:///base/path', false];
yield ['phar://C:/base/path/sub', 'phar://C:/base/path', false];
// second in first
yield ['/base/path', '/base/path/sub', true];
yield ['C:/base/path', 'C:/base/path/sub', true];
yield ['C:\\base\\path', 'C:\\base\\path\\sub', true];
yield ['C:/base/path', 'C:\\base\\path\\sub', true];
yield ['phar:///base/path', 'phar:///base/path/sub', true];
yield ['phar://C:/base/path', 'phar://C:/base/path/sub', true];
// first is prefix
yield ['/base/path/di', '/base/path/dir', false];
yield ['C:/base/path/di', 'C:/base/path/dir', false];
yield ['C:\\base\\path\\di', 'C:\\base\\path\\dir', false];
yield ['C:/base/path/di', 'C:\\base\\path\\dir', false];
yield ['phar:///base/path/di', 'phar:///base/path/dir', false];
yield ['phar://C:/base/path/di', 'phar://C:/base/path/dir', false];
// second is prefix
yield ['/base/path/dir', '/base/path/di', false];
yield ['C:/base/path/dir', 'C:/base/path/di', false];
yield ['C:\\base\\path\\dir', 'C:\\base\\path\\di', false];
yield ['C:/base/path/dir', 'C:\\base\\path\\di', false];
yield ['phar:///base/path/dir', 'phar:///base/path/di', false];
yield ['phar://C:/base/path/dir', 'phar://C:/base/path/di', false];
// root
yield ['/', '/second', true];
yield ['C:/', 'C:/second', true];
yield ['C:', 'C:/second', true];
yield ['C:\\', 'C:\\second', true];
yield ['C:/', 'C:\\second', true];
yield ['phar:///', 'phar:///second', true];
yield ['phar://C:/', 'phar://C:/second', true];
// windows vs unix
yield ['/base/path', 'C:/base/path', false];
yield ['C:/base/path', '/base/path', false];
yield ['/base/path', 'C:\\base\\path', false];
yield ['/base/path', 'phar:///base/path', false];
yield ['phar:///base/path', 'phar://C:/base/path', false];
// different partitions
yield ['C:/base/path', 'D:/base/path', false];
yield ['C:/base/path', 'D:\\base\\path', false];
yield ['C:\\base\\path', 'D:\\base\\path', false];
yield ['C:/base/path', 'phar://C:/base/path', false];
yield ['phar://C:/base/path', 'phar://D:/base/path', false];
}
/**
* @dataProvider provideIsBasePathTests
*/
public function testIsBasePath(string $path, string $ofPath, bool $result)
{
$this->assertSame($result, Path::isBasePath($path, $ofPath));
}
public static function provideJoinTests(): \Generator
{
yield [['', ''], ''];
yield [['/path/to/test', ''], '/path/to/test'];
yield [['/path/to//test', ''], '/path/to/test'];
yield [['', '/path/to/test'], '/path/to/test'];
yield [['', '/path/to//test'], '/path/to/test'];
yield [['/path/to/test', 'subdir'], '/path/to/test/subdir'];
yield [['/path/to/test/', 'subdir'], '/path/to/test/subdir'];
yield [['/path/to/test', '/subdir'], '/path/to/test/subdir'];
yield [['/path/to/test/', '/subdir'], '/path/to/test/subdir'];
yield [['/path/to/test', './subdir'], '/path/to/test/subdir'];
yield [['/path/to/test/', './subdir'], '/path/to/test/subdir'];
yield [['/path/to/test/', '../parentdir'], '/path/to/parentdir'];
yield [['/path/to/test', '../parentdir'], '/path/to/parentdir'];
yield [['path/to/test/', '/subdir'], 'path/to/test/subdir'];
yield [['path/to/test', '/subdir'], 'path/to/test/subdir'];
yield [['../path/to/test', '/subdir'], '../path/to/test/subdir'];
yield [['path', '../../subdir'], '../subdir'];
yield [['/path', '../../subdir'], '/subdir'];
yield [['../path', '../../subdir'], '../../subdir'];
yield [['/path/to/test', 'subdir', ''], '/path/to/test/subdir'];
yield [['/path/to/test', '/subdir', ''], '/path/to/test/subdir'];
yield [['/path/to/test/', 'subdir', ''], '/path/to/test/subdir'];
yield [['/path/to/test/', '/subdir', ''], '/path/to/test/subdir'];
yield [['/path', ''], '/path'];
yield [['/path', 'to', '/test', ''], '/path/to/test'];
yield [['/path', '', '/test', ''], '/path/test'];
yield [['path', 'to', 'test', ''], 'path/to/test'];
yield [[], ''];
yield [['base/path', 'to/test'], 'base/path/to/test'];
yield [['C:\\path\\to\\test', 'subdir'], 'C:/path/to/test/subdir'];
yield [['C:\\path\\to\\test\\', 'subdir'], 'C:/path/to/test/subdir'];
yield [['C:\\path\\to\\test', '/subdir'], 'C:/path/to/test/subdir'];
yield [['C:\\path\\to\\test\\', '/subdir'], 'C:/path/to/test/subdir'];
yield [['/', 'subdir'], '/subdir'];
yield [['/', '/subdir'], '/subdir'];
yield [['C:/', 'subdir'], 'C:/subdir'];
yield [['C:/', '/subdir'], 'C:/subdir'];
yield [['C:\\', 'subdir'], 'C:/subdir'];
yield [['C:\\', '/subdir'], 'C:/subdir'];
yield [['C:', 'subdir'], 'C:/subdir'];
yield [['C:', '/subdir'], 'C:/subdir'];
yield [['phar://', '/path/to/test'], 'phar:///path/to/test'];
yield [['phar:///', '/path/to/test'], 'phar:///path/to/test'];
yield [['phar:///path/to/test', 'subdir'], 'phar:///path/to/test/subdir'];
yield [['phar:///path/to/test', 'subdir/'], 'phar:///path/to/test/subdir'];
yield [['phar:///path/to/test', '/subdir'], 'phar:///path/to/test/subdir'];
yield [['phar:///path/to/test/', 'subdir'], 'phar:///path/to/test/subdir'];
yield [['phar:///path/to/test/', '/subdir'], 'phar:///path/to/test/subdir'];