Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace AppService ;
- use AppModelsProduct ;
- use IlluminateHttpRequest ;
- use Image ;
- use AppModelsCategory;
- use Storage ;
- class ProductService{
- public function save($request, $product='')
- {
- $thumb = [] ;
- $data = array_merge($request,$thumb);
- if($product instanceof Product)
- {
- $product->update($data);
- }
- else
- {
- $product = Product::create($data);
- }
- return $product ;
- }
- namespace AppHttpControllersAdmin;
- use AppModelsProduct;
- use IlluminateHttpRequest;
- use AppHttpControllersController;
- use AppHttpTraitsProductTraits ;
- use AppHttpRequestsSaveProduct ;
- use AppServiceProductService ;
- use AppServiceProductSearchService ;
- use AppEventsProductUpdated ;
- use AppServiceCategoryService ;
- use Storage ;
- class ProductController extends Controller
- {
- use ProductTraits ;
- private $ProductService ;
- public function __construct(ProductService $productservice)
- {
- $this->ProductService = $productservice ;
- }
- public function store(Request $request)
- {
- $this->ProductService->save($request->all());
- return redirect()->route('products.index');
- }
- }
- namespace TestsUnit;
- use TestsTestCase;
- use IlluminateFoundationTestingWithFaker;
- use IlluminateFoundationTestingRefreshDatabase;
- //use AppServiceProductService ;
- class ProductTest extends TestCase
- {
- /**
- * A basic test example.
- *
- * @return void
- */
- public function testExample()
- {
- $this->assertTrue(true);
- }
- public function testAddProduct()
- {
- $productService = Mockery::mock('AppServiceProductService');
- $data = ['name' => 'test', 'product_sn' => '123456', 'category_id' =>15, 'description' =>'description'] ;
- $productService->shouldReceive('save')->with($data, '')->once();
- $this->app->instance('AppServiceProductService', $productService);
- $response = $this->post('admin/products');
- $response->assertRedirect('admin/products');
- }
- public function tearDown() {
- Mockery::close();
- }
- }
Add Comment
Please, Sign In to add comment