9
9
use Prophecy \PhpUnit \ProphecyTrait ;
10
10
use Prophecy \Prophecy \ObjectProphecy ;
11
11
use Psr \Container \ContainerInterface ;
12
+ use Yokai \Batch \BatchStatus ;
12
13
use Yokai \Batch \Factory \JobExecutionFactory ;
13
14
use Yokai \Batch \Factory \UniqidJobExecutionIdGenerator ;
14
15
use Yokai \Batch \Job \JobInterface ;
@@ -58,15 +59,10 @@ public function testLaunch(): void
58
59
59
60
public function testLaunchJobCatchException (): void
60
61
{
61
- $ jobExecutionAssertions = Argument::allOf (
62
- Argument::type (JobExecution::class),
63
- Argument::which ('getJobName ' , 'export ' )
64
- );
65
62
/** @var ObjectProphecy|JobInterface $job */
66
63
$ job = $ this ->prophesize (JobInterface::class);
67
- $ job ->execute ($ jobExecutionAssertions )
68
- ->shouldBeCalledTimes (1 )
69
- ->willThrow (new \Exception ());
64
+ $ job ->execute (Argument::any ())
65
+ ->willThrow (new \Exception ('Triggered for test purpose ' ));
70
66
71
67
/** @var ContainerInterface|ObjectProphecy $container */
72
68
$ container = $ this ->prophesize (ContainerInterface::class);
@@ -78,22 +74,20 @@ public function testLaunchJobCatchException(): void
78
74
$ jobExecutionStorage = $ this ->prophesize (JobExecutionStorageInterface::class);
79
75
80
76
$ launcher = new SimpleJobLauncher ($ jobRegistry , $ jobExecutionFactory , $ jobExecutionStorage ->reveal (), null );
81
- $ launcher ->launch ('export ' );
77
+ $ execution = $ launcher ->launch ('export ' );
78
+
79
+ self ::assertSame ('export ' , $ execution ->getJobName ());
80
+ self ::assertTrue ($ execution ->getStatus ()->is (BatchStatus::FAILED ));
81
+ self ::assertSame (\Exception::class, $ execution ->getFailures ()[0 ]->getClass ());
82
+ self ::assertSame ('Triggered for test purpose ' , $ execution ->getFailures ()[0 ]->getMessage ());
82
83
}
83
84
84
85
public function testLaunchJobCatchFatal (): void
85
86
{
86
- $ jobExecutionAssertions = Argument::allOf (
87
- Argument::type (JobExecution::class),
88
- Argument::which ('getJobName ' , 'export ' )
89
- );
90
87
/** @var ObjectProphecy|JobInterface $job */
91
88
$ job = $ this ->prophesize (JobInterface::class);
92
- $ job ->execute ($ jobExecutionAssertions )
93
- ->shouldBeCalledTimes (1 )
94
- ->will (function (): void {
95
- $ var = 10 / 0 ;
96
- });
89
+ $ job ->execute (Argument::any ())
90
+ ->willThrow (new \DivisionByZeroError ('Triggered for test purpose ' ));
97
91
98
92
/** @var ContainerInterface|ObjectProphecy $container */
99
93
$ container = $ this ->prophesize (ContainerInterface::class);
@@ -105,6 +99,11 @@ public function testLaunchJobCatchFatal(): void
105
99
$ jobExecutionStorage = $ this ->prophesize (JobExecutionStorageInterface::class);
106
100
107
101
$ launcher = new SimpleJobLauncher ($ jobRegistry , $ jobExecutionFactory , $ jobExecutionStorage ->reveal (), null );
108
- $ launcher ->launch ('export ' );
102
+ $ execution = $ launcher ->launch ('export ' );
103
+
104
+ self ::assertSame ('export ' , $ execution ->getJobName ());
105
+ self ::assertTrue ($ execution ->getStatus ()->is (BatchStatus::FAILED ));
106
+ self ::assertSame (\DivisionByZeroError::class, $ execution ->getFailures ()[0 ]->getClass ());
107
+ self ::assertSame ('Triggered for test purpose ' , $ execution ->getFailures ()[0 ]->getMessage ());
109
108
}
110
109
}
0 commit comments