1+ <?php
2+
3+ /*
4+ * This file is part of the Symfony package.
5+ *
6+ * (c) Fabien Potencier <[email protected] > 7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Symfony \Flex \Tests ;
13+
14+ use Composer \IO \IOInterface ;
15+ use PHPUnit \Framework \TestCase ;
16+ use Symfony \Flex \Options ;
17+
18+ class OptionsTest extends TestCase
19+ {
20+ public function testShouldWrite (): void
21+ {
22+ $ this ->assertTrue ((new Options ([], null ))->shouldWriteFile ('non-existing-file.txt ' , false , false ));
23+ $ this ->assertFalse ((new Options ([], null ))->shouldWriteFile (__FILE__ , false , false ));
24+
25+ // We don't have an IO, so we don't write the file
26+ $ this ->assertFalse ((new Options ([], null ))->shouldWriteFile (__FILE__ , true , false ));
27+
28+ // We have an IO, and it allowed to write the file
29+ $ io = $ this ->createMock (IOInterface::class);
30+ $ io ->expects ($ this ->once ())->method ('askConfirmation ' )->willReturn (true );
31+ $ this ->assertTrue ((new Options ([], $ io ))->shouldWriteFile (__FILE__ , true , false ));
32+
33+ // We skip all questions, so we're able to write
34+ $ this ->assertTrue ((new Options ([], null ))->shouldWriteFile (__FILE__ , true , true ));
35+ }
36+ }
0 commit comments