@@ -38,55 +38,44 @@ protected function setUp(): void
38
38
39
39
public function testDumpPages ()
40
40
{
41
- $ fs = new Filesystem ();
42
- $ fs ->mkdir ($ this ->tmpDir );
43
- $ fs ->touch ($ this ->tmpDir .\DIRECTORY_SEPARATOR .'400.html ' );
44
-
45
41
$ tester = $ this ->getCommandTester ($ this ->getKernel (), []);
46
- $ tester ->execute ([]);
42
+ $ tester ->execute ([
43
+ 'path ' => $ this ->tmpDir ,
44
+ ]);
47
45
48
- $ this ->assertFileExists ($ this ->tmpDir .\DIRECTORY_SEPARATOR .'400.html ' );
49
46
$ this ->assertFileExists ($ this ->tmpDir .\DIRECTORY_SEPARATOR .'404.html ' );
50
47
$ this ->assertStringContainsString ('Error 404 ' , file_get_contents ($ this ->tmpDir .\DIRECTORY_SEPARATOR .'404.html ' ));
51
48
}
52
49
53
50
public function testDumpPagesOnlyForGivenStatusCodes ()
54
51
{
52
+ $ fs = new Filesystem ();
53
+ $ fs ->mkdir ($ this ->tmpDir );
54
+ $ fs ->touch ($ this ->tmpDir .\DIRECTORY_SEPARATOR .'test.html ' );
55
+
55
56
$ tester = $ this ->getCommandTester ($ this ->getKernel ());
56
57
$ tester ->execute ([
58
+ 'path ' => $ this ->tmpDir ,
57
59
'status-codes ' => ['400 ' , '500 ' ],
58
60
]);
59
61
62
+ $ this ->assertFileExists ($ this ->tmpDir .\DIRECTORY_SEPARATOR .'test.html ' );
60
63
$ this ->assertFileDoesNotExist ($ this ->tmpDir .\DIRECTORY_SEPARATOR .'404.html ' );
61
64
62
65
$ this ->assertFileExists ($ this ->tmpDir .\DIRECTORY_SEPARATOR .'400.html ' );
63
66
$ this ->assertStringContainsString ('Error 400 ' , file_get_contents ($ this ->tmpDir .\DIRECTORY_SEPARATOR .'400.html ' ));
64
67
}
65
68
66
- public function testDumpPagesAtCustomPath ()
69
+ public function testForceRemovalPages ()
67
70
{
68
- $ path = sys_get_temp_dir ().'/error_pages_custom ' ;
69
-
70
71
$ fs = new Filesystem ();
71
- $ fs ->remove ($ path );
72
-
73
- $ tester = $ this ->getCommandTester ($ this ->getKernel ());
74
- $ tester ->execute ([
75
- '--path ' => $ path ,
76
- ]);
77
-
78
- $ this ->assertFileExists ($ path .\DIRECTORY_SEPARATOR .'400.html ' );
79
- $ this ->assertStringContainsString ('Error 400 ' , file_get_contents ($ path .\DIRECTORY_SEPARATOR .'400.html ' ));
80
- }
81
-
82
- public function testClearPages ()
83
- {
84
- mkdir ($ this ->tmpDir );
85
- touch ($ this ->tmpDir .\DIRECTORY_SEPARATOR .'test.html ' );
72
+ $ fs ->mkdir ($ this ->tmpDir );
73
+ $ fs ->touch ($ this ->tmpDir .\DIRECTORY_SEPARATOR .'test.html ' );
86
74
87
75
$ tester = $ this ->getCommandTester ($ this ->getKernel ());
88
76
$ tester ->execute ([
89
- '--clear ' => true ,
77
+ 'path ' => $ this ->tmpDir ,
78
+ '--force ' => true ,
90
79
]);
91
80
92
81
$ this ->assertFileDoesNotExist ($ this ->tmpDir .\DIRECTORY_SEPARATOR .'test.html ' );
@@ -95,27 +84,14 @@ public function testClearPages()
95
84
96
85
private function getKernel (): MockObject &KernelInterface
97
86
{
98
- $ kernel = $ this ->createMock (KernelInterface::class);
99
- $ kernel
100
- ->expects ($ this ->any ())
101
- ->method ('getContainer ' )
102
- ->willReturn (new Container ());
103
-
104
- $ kernel
105
- ->expects ($ this ->once ())
106
- ->method ('getBundles ' )
107
- ->willReturn ([]);
108
-
109
- return $ kernel ;
87
+ return $ this ->createMock (KernelInterface::class);
110
88
}
111
89
112
90
private function getCommandTester (KernelInterface $ kernel ): CommandTester
113
91
{
114
- $ errorRenderer = $ this ->createMock (ErrorRendererInterface::class);
92
+ $ errorRenderer = $ this ->createStub (ErrorRendererInterface::class);
115
93
$ errorRenderer
116
- ->expects ($ this ->any ())
117
94
->method ('render ' )
118
- ->with ($ this ->isInstanceOf (HttpException::class))
119
95
->willReturnCallback (function (HttpException $ e ) {
120
96
$ exception = FlattenException::createFromThrowable ($ e );
121
97
$ exception ->setAsString (\sprintf ('<html><body>Error %s</body></html> ' , $ e ->getStatusCode ()));
@@ -125,14 +101,9 @@ private function getCommandTester(KernelInterface $kernel): CommandTester
125
101
;
126
102
127
103
$ entrypointLookup = $ this ->createMock (EntrypointLookupInterface::class);
128
- $ entrypointLookup
129
- ->expects ($ this ->any ())
130
- ->method ('reset ' )
131
- ;
132
104
133
105
$ application = new Application ($ kernel );
134
106
$ application ->add (new ErrorDumpCommand (
135
- $ this ->tmpDir ,
136
107
new Filesystem (),
137
108
$ errorRenderer ,
138
109
$ entrypointLookup ,
0 commit comments