|
|
@@ -78,28 +78,71 @@ class CreateByBatchTest extends TestCase
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+ function subMock(array $serviceDefinition){
|
|
|
+ $mockingService=$this->createPartialMock(
|
|
|
+ $serviceDefinition['class'],
|
|
|
+ array_keys($serviceDefinition['methods'])
|
|
|
+ );
|
|
|
+ foreach ($serviceDefinition['methods'] as $mName=>$mVal){
|
|
|
+ $mockingService->method($mName)->willReturn($mVal);
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($serviceDefinition['subServices'] as $subService){
|
|
|
+ $mockingService->instant(
|
|
|
+ $subService['serviceName'],
|
|
|
+ ($subServiceMock=function()use($subService){
|
|
|
+ $subServiceMock=$this->createPartialMock(
|
|
|
+ $subService['class'],
|
|
|
+ array_keys($subService['methods'])
|
|
|
+ );
|
|
|
+ foreach ($subService['methods'] as $methodName=>$methodVal){
|
|
|
+ $subServiceMock->method($methodName)->willReturn($methodVal);
|
|
|
+ }
|
|
|
+ return $subServiceMock;
|
|
|
+ })()
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return $mockingService;
|
|
|
+ }
|
|
|
+
|
|
|
public function testReturned()
|
|
|
{
|
|
|
- $stationTypeServiceMock=( function (){
|
|
|
- $stationTypeServiceMock=$this->createPartialMock(
|
|
|
- StationTypeService::class,
|
|
|
- ['aaa']
|
|
|
- );
|
|
|
- $stationRuleBatchServiceStr = 'stationRuleBatchService';
|
|
|
- $stationTypeServiceMock->instant(
|
|
|
- $stationRuleBatchServiceStr,
|
|
|
- ($stationRuleBatchServiceMock=function(){
|
|
|
- $mock=$this->createPartialMock(
|
|
|
- StationRuleBatchService::class,
|
|
|
- ['getByBatch']
|
|
|
- );
|
|
|
- $mock->method('getByBatch')->willReturn('ddd');
|
|
|
- return $mock;
|
|
|
- })()
|
|
|
- );
|
|
|
- return $stationTypeServiceMock;
|
|
|
- })();
|
|
|
+ $stationTypeServiceMock=$this->subMock([
|
|
|
+ 'class'=>StationTypeService::class,
|
|
|
+ 'methods'=>[
|
|
|
+// 'getByBatch'=>111,
|
|
|
+ ],
|
|
|
+ 'subServices'=>[
|
|
|
+ [
|
|
|
+ 'serviceName'=>'stationRuleBatchService',
|
|
|
+ 'class'=>stationRuleBatchService::class,
|
|
|
+ 'methods'=>[
|
|
|
+ 'getByBatch'=>4242,
|
|
|
+ 'aaa'=>222,
|
|
|
+ ],
|
|
|
+ ],
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
dd($stationTypeServiceMock->getByBatch(new Batch()));
|
|
|
+// $stationTypeServiceMock=( function (){
|
|
|
+// $stationTypeServiceMock=$this->createPartialMock(
|
|
|
+// StationTypeService::class,
|
|
|
+// ['aaa']
|
|
|
+// );
|
|
|
+// $stationRuleBatchServiceStr = 'stationRuleBatchService';
|
|
|
+// $stationTypeServiceMock->instant(
|
|
|
+// $stationRuleBatchServiceStr,
|
|
|
+// ($stationRuleBatchServiceMock=function(){
|
|
|
+// $mock=$this->createPartialMock(
|
|
|
+// StationRuleBatchService::class,
|
|
|
+// ['getByBatch']
|
|
|
+// );
|
|
|
+// $mock->method('getByBatch')->willReturn('ddd');
|
|
|
+// return $mock;
|
|
|
+// })()
|
|
|
+// );
|
|
|
+// return $stationTypeServiceMock;
|
|
|
+// })();
|
|
|
|
|
|
|
|
|
$this->data['stationTaskCommodities']
|
|
|
@@ -109,7 +152,7 @@ class CreateByBatchTest extends TestCase
|
|
|
foreach($this->data['batches'] as $batch){
|
|
|
$this->data['stationTaskCommodities']
|
|
|
=$this->data['stationTaskCommodities']->merge(
|
|
|
- $this->service->createByBatch($batch)//<<---testing it
|
|
|
+ $this->service->createByBatch($batch)//<<---testing it
|
|
|
);
|
|
|
}
|
|
|
return $this->data['stationTaskCommodities'];
|