File tree 3 files changed +28
-29
lines changed
Configuration/Xml/Migration
tests/end-to-end/migration
3 files changed +28
-29
lines changed Original file line number Diff line number Diff line change 11
11
12
12
use function copy ;
13
13
use function file_put_contents ;
14
+ use function sprintf ;
14
15
use PHPUnit \TextUI \XmlConfiguration \Migrator ;
15
16
use Throwable ;
16
17
@@ -28,24 +29,33 @@ public function __construct(string $filename)
28
29
29
30
public function execute (): Result
30
31
{
31
- copy ($ this ->filename , $ this ->filename . '.bak ' );
32
+ try {
33
+ $ migrated = (new Migrator )->migrate ($ this ->filename );
32
34
33
- $ buffer = 'Created backup: ' . $ this ->filename . '.bak ' . PHP_EOL ;
34
- $ shellExitCode = Result::SUCCESS ;
35
+ copy ($ this ->filename , $ this ->filename . '.bak ' );
35
36
36
- try {
37
- file_put_contents (
38
- $ this ->filename ,
39
- (new Migrator )->migrate ($ this ->filename ),
40
- );
37
+ file_put_contents ($ this ->filename , $ migrated );
41
38
42
- $ buffer .= 'Migrated configuration: ' . $ this ->filename . PHP_EOL ;
39
+ return Result::from (
40
+ sprintf (
41
+ 'Created backup: %s.bak%sMigrated configuration: %s%s ' ,
42
+ $ this ->filename ,
43
+ PHP_EOL ,
44
+ $ this ->filename ,
45
+ PHP_EOL ,
46
+ ),
47
+ );
43
48
} catch (Throwable $ t ) {
44
- $ buffer .= 'Migration failed: ' . $ t ->getMessage () . PHP_EOL ;
45
-
46
- $ shellExitCode = Result::FAILURE ;
49
+ return Result::from (
50
+ sprintf (
51
+ 'Migration of %s failed:%s%s%s ' ,
52
+ $ this ->filename ,
53
+ PHP_EOL ,
54
+ $ t ->getMessage (),
55
+ PHP_EOL ,
56
+ ),
57
+ Result::FAILURE ,
58
+ );
47
59
}
48
-
49
- return Result::from ($ buffer , $ shellExitCode );
50
60
}
51
61
}
Original file line number Diff line number Diff line change 9
9
*/
10
10
namespace PHPUnit \TextUI \XmlConfiguration ;
11
11
12
- use function sprintf ;
13
12
use PHPUnit \Runner \Version ;
14
13
use PHPUnit \Util \Xml \Loader as XmlLoader ;
15
14
use PHPUnit \Util \Xml \XmlException ;
@@ -30,21 +29,11 @@ public function migrate(string $filename): string
30
29
$ origin = (new SchemaDetector )->detect ($ filename );
31
30
32
31
if (!$ origin ->detected ()) {
33
- throw new Exception (
34
- sprintf (
35
- '%s does not validate against any know schema ' ,
36
- $ filename ,
37
- ),
38
- );
32
+ throw new Exception ('The file does not validate against any know schema ' );
39
33
}
40
34
41
35
if ($ origin ->version () === Version::series ()) {
42
- throw new Exception (
43
- sprintf (
44
- '%s does not need to be migrated ' ,
45
- $ filename ,
46
- ),
47
- );
36
+ throw new Exception ('The file does not need to be migrated ' );
48
37
}
49
38
50
39
$ configurationDocument = (new XmlLoader )->loadFile ($ filename );
Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ require_once __DIR__ . '/../../bootstrap.php';
14
14
--EXPECTF --
15
15
PHPUnit %s by Sebastian Bergmann and contributors.
16
16
17
- Created backup: %sphpunit.xml.bak
18
- Migration failed: %s does not validate against any know schema
17
+ Migration of %s failed:
18
+ The file does not validate against any know schema
19
19
--CLEAN --
20
20
<?php declare (strict_types=1 );
21
21
unlink (sys_get_temp_dir () . '/phpunit.xml ' );
You can’t perform that action at this time.
0 commit comments