33namespace IonBazan \ComposerDiff \Tests \Formatter ;
44
55use Composer \DependencyResolver \Operation \InstallOperation ;
6+ use Composer \DependencyResolver \Operation \OperationInterface ;
67use Composer \DependencyResolver \Operation \UninstallOperation ;
78use Composer \DependencyResolver \Operation \UpdateOperation ;
89use Composer \Package \PackageInterface ;
@@ -43,29 +44,22 @@ public function testGetProjectUrlReturnsNullForInvalidOperation()
4344
4445 /**
4546 * @param bool $withUrls
47+ * @param bool $decorated
4648 *
4749 * @testWith [false]
4850 * [true]
51+ * [false, true]
52+ * [true, true]
4953 */
50- public function testItRendersTheListOfOperations ($ withUrls )
54+ public function testItRendersTheListOfOperations ($ withUrls, $ decorated = false )
5155 {
52- $ output = new StreamOutput (fopen ('php://memory ' , 'wb ' , false ));
53- $ formatter = $ this ->getFormatter ($ output , $ this ->getGenerators ());
54- $ prodPackages = array (
55- new InstallOperation ($ this ->getPackage ('a/package-1 ' , '1.0.0 ' )),
56- new InstallOperation ($ this ->getPackage ('a/no-link-1 ' , '1.0.0 ' )),
57- new UpdateOperation ($ this ->getPackage ('a/package-2 ' , '1.0.0 ' ), $ this ->getPackage ('a/package-2 ' , '1.2.0 ' )),
58- new UpdateOperation ($ this ->getPackage ('a/package-3 ' , '2.0.0 ' ), $ this ->getPackage ('a/package-3 ' , '1.1.1 ' )),
59- new UpdateOperation ($ this ->getPackage ('a/no-link-2 ' , '2.0.0 ' ), $ this ->getPackage ('a/no-link-2 ' , '1.1.1 ' )),
60- new UpdateOperation ($ this ->getPackage ('php ' , '>=7.4.6 ' ), $ this ->getPackage ('php ' , '^8.0 ' )),
56+ $ output = new StreamOutput (fopen ('php://memory ' , 'wb ' , false ), OutputInterface::VERBOSITY_NORMAL , $ decorated );
57+ $ this ->getFormatter ($ output , $ this ->getGenerators ())->render (
58+ $ this ->getEntries ($ this ->getSampleProdOperations ()),
59+ $ this ->getEntries ($ this ->getSampleDevOperations ()),
60+ $ withUrls
6161 );
62- $ devPackages = array (
63- new UpdateOperation ($ this ->getPackage ('a/package-5 ' , 'dev-master ' , 'dev-master 1234567 ' ), $ this ->getPackage ('a/package-5 ' , '1.1.1 ' )),
64- new UninstallOperation ($ this ->getPackage ('a/package-4 ' , '0.1.1 ' )),
65- new UninstallOperation ($ this ->getPackage ('a/no-link-2 ' , '0.1.1 ' )),
66- );
67- $ formatter ->render ($ this ->getEntries ($ prodPackages ), $ this ->getEntries ($ devPackages ), $ withUrls );
68- $ this ->assertSame ($ this ->getSampleOutput ($ withUrls ), $ this ->getDisplay ($ output ));
62+ $ this ->assertSame ($ this ->getSampleOutput ($ withUrls , $ decorated ), $ this ->getDisplay ($ output ));
6963 }
7064
7165 public function testItFailsWithInvalidOperation ()
@@ -84,10 +78,11 @@ abstract protected function getFormatter(OutputInterface $output, GeneratorConta
8478
8579 /**
8680 * @param bool $withUrls
81+ * @param bool $decorated
8782 *
8883 * @return string
8984 */
90- abstract protected function getSampleOutput ($ withUrls );
85+ abstract protected function getSampleOutput ($ withUrls, $ decorated );
9186
9287 /**
9388 * @return string
@@ -107,6 +102,14 @@ protected function getDisplay(OutputInterface $output)
107102 return stream_get_contents ($ output ->getStream ());
108103 }
109104
105+ /**
106+ * @return bool
107+ */
108+ protected function supportsLinks ()
109+ {
110+ return method_exists ('Symfony\Component\Console\Formatter\OutputFormatterStyle ' , 'setHref ' );
111+ }
112+
110113 /**
111114 * @return MockObject|GeneratorContainer
112115 */
@@ -125,6 +128,7 @@ protected function getGenerators()
125128
126129 $ generators = $ this ->getMockBuilder ('IonBazan\ComposerDiff\Url\GeneratorContainer ' )
127130 ->disableOriginalConstructor ()
131+ ->setMethods (array ('get ' ))
128132 ->getMock ();
129133 $ generators ->method ('get ' )
130134 ->willReturnCallback (function (PackageInterface $ package ) use ($ generator ) {
@@ -137,4 +141,31 @@ protected function getGenerators()
137141
138142 return $ generators ;
139143 }
144+
145+ /**
146+ * @return OperationInterface[]
147+ */
148+ private function getSampleProdOperations ()
149+ {
150+ return array (
151+ new InstallOperation ($ this ->getPackage ('a/package-1 ' , '1.0.0 ' )),
152+ new InstallOperation ($ this ->getPackage ('a/no-link-1 ' , '1.0.0 ' )),
153+ new UpdateOperation ($ this ->getPackage ('a/package-2 ' , '1.0.0 ' ), $ this ->getPackage ('a/package-2 ' , '1.2.0 ' )),
154+ new UpdateOperation ($ this ->getPackage ('a/package-3 ' , '2.0.0 ' ), $ this ->getPackage ('a/package-3 ' , '1.1.1 ' )),
155+ new UpdateOperation ($ this ->getPackage ('a/no-link-2 ' , '2.0.0 ' ), $ this ->getPackage ('a/no-link-2 ' , '1.1.1 ' )),
156+ new UpdateOperation ($ this ->getPackage ('php ' , '>=7.4.6 ' ), $ this ->getPackage ('php ' , '^8.0 ' )),
157+ );
158+ }
159+
160+ /**
161+ * @return OperationInterface[]
162+ */
163+ private function getSampleDevOperations ()
164+ {
165+ return array (
166+ new UpdateOperation ($ this ->getPackage ('a/package-5 ' , 'dev-master ' , 'dev-master 1234567 ' ), $ this ->getPackage ('a/package-5 ' , '1.1.1 ' )),
167+ new UninstallOperation ($ this ->getPackage ('a/package-4 ' , '0.1.1 ' )),
168+ new UninstallOperation ($ this ->getPackage ('a/no-link-2 ' , '0.1.1 ' )),
169+ );
170+ }
140171}
0 commit comments