Guest User

Untitled

a guest
Mar 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. namespace AppService ;
  2. use AppModelsProduct ;
  3. use IlluminateHttpRequest ;
  4. use Image ;
  5. use AppModelsCategory;
  6. use Storage ;
  7.  
  8. class ProductService{
  9.  
  10. public function save($request, $product='')
  11. {
  12. $thumb = [] ;
  13. $data = array_merge($request,$thumb);
  14. if($product instanceof Product)
  15. {
  16. $product->update($data);
  17.  
  18. }
  19. else
  20. {
  21. $product = Product::create($data);
  22. }
  23.  
  24. return $product ;
  25. }
  26.  
  27. namespace AppHttpControllersAdmin;
  28. use AppModelsProduct;
  29. use IlluminateHttpRequest;
  30. use AppHttpControllersController;
  31. use AppHttpTraitsProductTraits ;
  32. use AppHttpRequestsSaveProduct ;
  33. use AppServiceProductService ;
  34. use AppServiceProductSearchService ;
  35. use AppEventsProductUpdated ;
  36. use AppServiceCategoryService ;
  37. use Storage ;
  38.  
  39. class ProductController extends Controller
  40. {
  41. use ProductTraits ;
  42. private $ProductService ;
  43. public function __construct(ProductService $productservice)
  44. {
  45. $this->ProductService = $productservice ;
  46. }
  47.  
  48. public function store(Request $request)
  49. {
  50. $this->ProductService->save($request->all());
  51.  
  52. return redirect()->route('products.index');
  53. }
  54. }
  55.  
  56. namespace TestsUnit;
  57. use TestsTestCase;
  58. use IlluminateFoundationTestingWithFaker;
  59. use IlluminateFoundationTestingRefreshDatabase;
  60. //use AppServiceProductService ;
  61.  
  62. class ProductTest extends TestCase
  63. {
  64. /**
  65. * A basic test example.
  66. *
  67. * @return void
  68. */
  69. public function testExample()
  70. {
  71. $this->assertTrue(true);
  72. }
  73.  
  74. public function testAddProduct()
  75. {
  76. $productService = Mockery::mock('AppServiceProductService');
  77. $data = ['name' => 'test', 'product_sn' => '123456', 'category_id' =>15, 'description' =>'description'] ;
  78.  
  79. $productService->shouldReceive('save')->with($data, '')->once();
  80.  
  81. $this->app->instance('AppServiceProductService', $productService);
  82.  
  83. $response = $this->post('admin/products');
  84. $response->assertRedirect('admin/products');
  85.  
  86. }
  87.  
  88. public function tearDown() {
  89. Mockery::close();
  90. }
  91. }
Add Comment
Please, Sign In to add comment