1+ <?php
2+
3+ namespace App \Tests \Service ;
4+
5+ use App \Model \DependencyFileFormat ;
6+ use App \Service \FileGroupFinder ;
7+ use App \Tests \Command \FindAndUploadFilesCommandTest ;
8+ use PHPUnit \Framework \TestCase ;
9+ use Symfony \Component \Finder \Finder ;
10+ use Symfony \Component \Finder \SplFileInfo ;
11+
12+ class CreateFileGroupsTest extends TestCase
13+ {
14+ public function testCreateFileGroups (): void
15+ {
16+ $ iterator = [
17+ new SplFileInfo ('package.json ' , 'app ' , 'app/package.json ' ),
18+ new SplFileInfo ('package-lock.json ' , 'app ' , 'app/package-lock.json ' ),
19+ ];
20+ $ iterator = new \ArrayIterator ($ iterator );
21+
22+ $ finderMock = $ this ->getMockBuilder (Finder::class)->disableOriginalConstructor ()->getMock ();
23+ $ finderMock ->expects ($ this ->once ())->method ('getIterator ' )->willReturn ($ iterator );
24+ $ dependencyFileFormats = DependencyFileFormat::make (
25+ \json_decode (FindAndUploadFilesCommandTest::FORMATS_JSON_STRING , true )
26+ );
27+
28+ $ lockFiles = ['app/package-lock.json ' => new SplFileInfo ('package-lock.json ' , 'app ' , 'app/package-lock.json ' )];
29+ $ fileGroups = FileGroupFinder::createFileGroups ($ lockFiles , $ finderMock , $ dependencyFileFormats , '. ' );
30+
31+ $ this ->assertCount (1 , $ fileGroups );
32+ $ fileGroup = $ fileGroups [0 ];
33+ $ this ->assertInstanceOf (\SplFileInfo::class, $ fileGroup ->getDependencyFile ());
34+ $ this ->assertNotEmpty ($ fileGroup ->getLockFiles ());
35+ $ this ->assertCount (1 , $ fileGroup ->getLockFiles ());
36+ $ lockFile = $ fileGroup ->getLockFiles ()[0 ];
37+ $ this ->assertInstanceOf (\SplFileInfo::class, $ lockFile );
38+ }
39+
40+ public function testCreateFileGroupsOnWindows (): void
41+ {
42+ $ iterator = [
43+ new SplFileInfo ('package.json ' , 'app ' , 'app\package.json ' ),
44+ new SplFileInfo ('package-lock.json ' , 'app ' , 'app\package-lock.json ' ),
45+ ];
46+ $ iterator = new \ArrayIterator ($ iterator );
47+
48+ $ finderMock = $ this ->getMockBuilder (Finder::class)->disableOriginalConstructor ()->getMock ();
49+ $ finderMock ->expects ($ this ->once ())->method ('getIterator ' )->willReturn ($ iterator );
50+ $ dependencyFileFormats = DependencyFileFormat::make (
51+ \json_decode (FindAndUploadFilesCommandTest::FORMATS_JSON_STRING , true )
52+ );
53+
54+ $ lockFiles = ['app\package-lock.json ' => new SplFileInfo ('package-lock.json ' , 'app ' , 'app\package-lock.json ' )];
55+ $ fileGroups = FileGroupFinder::createFileGroups ($ lockFiles , $ finderMock , $ dependencyFileFormats , '. ' );
56+
57+ $ this ->assertCount (1 , $ fileGroups );
58+ $ fileGroup = $ fileGroups [0 ];
59+ $ this ->assertInstanceOf (\SplFileInfo::class, $ fileGroup ->getDependencyFile ());
60+ $ this ->assertNotEmpty ($ fileGroup ->getLockFiles ());
61+ $ this ->assertCount (1 , $ fileGroup ->getLockFiles ());
62+ $ lockFile = $ fileGroup ->getLockFiles ()[0 ];
63+ $ this ->assertInstanceOf (\SplFileInfo::class, $ lockFile );
64+ }
65+ }
0 commit comments