function it_applies_on_related_products($saver, RemoveEvent $event, CategoryInterface $object, ProductInterface $product)
 {
     $saver->saveAll([$product], ['flush' => 'expected_flush_value', 'recalculate' => false, 'schedule' => false])->shouldBeCalled();
     $event->getSubject()->willReturn($object);
     $event->getArgument('flush')->willReturn('expected_flush_value');
     $object->getProducts()->willReturn([$product]);
     $product->removeCategory($object)->shouldBeCalled();
     $this->postRemove($event)->shouldReturn(null);
 }
 /**
  * @param RemoveEvent $event
  */
 public function postRemove(RemoveEvent $event)
 {
     $subject = $event->getSubject();
     if (!$subject instanceof CategoryInterface) {
         return;
     }
     $productsToUpdate = [];
     foreach ($subject->getProducts() as $product) {
         $product->removeCategory($subject);
         $productsToUpdate[] = $product;
     }
     if (count($productsToUpdate) > 0) {
         $this->saver->saveAll($productsToUpdate, ['flush' => $event->getArgument('flush'), 'recalculate' => false, 'schedule' => false]);
     }
 }