partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

StockHistoryLostTest.php (2566B)


      1 <?php
      2 
      3 namespace PartKeepr\PartBundle\Tests\Issues;
      4 
      5 use Doctrine\Common\DataFixtures\ProxyReferenceRepository;
      6 use PartKeepr\CoreBundle\Tests\WebTestCase;
      7 use PartKeepr\PartBundle\Entity\Part;
      8 use PartKeepr\StockBundle\Entity\StockEntry;
      9 
     10 /**
     11  * Class StockHistoryLostTest.
     12  *
     13  * Unit test against issue #551 (stock history gets removed after saving part)
     14  */
     15 class StockHistoryLostTest extends WebTestCase
     16 {
     17     /**
     18      * @var ProxyReferenceRepository
     19      */
     20     protected $fixtures;
     21 
     22     public function setUp()
     23     {
     24         $this->fixtures = $this->loadFixtures(
     25             [
     26                 'PartKeepr\StorageLocationBundle\DataFixtures\CategoryDataLoader',
     27                 'PartKeepr\StorageLocationBundle\DataFixtures\StorageLocationLoader',
     28                 'PartKeepr\PartBundle\DataFixtures\CategoryDataLoader',
     29                 'PartKeepr\PartBundle\DataFixtures\PartDataLoader',
     30                 'PartKeepr\AuthBundle\DataFixtures\LoadUserData',
     31                 'PartKeepr\ManufacturerBundle\Tests\DataFixtures\ManufacturerDataLoader',
     32                 'PartKeepr\DistributorBundle\Tests\DataFixtures\DistributorDataLoader',
     33             ]
     34         )->getReferenceRepository();
     35     }
     36 
     37     public function testStockHistory()
     38     {
     39         $client = static::makeClient(true);
     40 
     41         /**
     42          * @var Part
     43          */
     44         $part1 = $this->fixtures->getReference('part.1');
     45 
     46         $stockLevel = new StockEntry();
     47         $stockLevel->setPart($part1);
     48         $stockLevel->setStockLevel(5);
     49 
     50         $fosUser = $this->fixtures->getReference('user.admin');
     51         $userService = $this->getContainer()->get('partkeepr.userservice');
     52         $user = $userService->getProxyUser($fosUser->getUsername(), $userService->getBuiltinProvider(), true);
     53 
     54         $stockLevel->setUser($user);
     55         $part1->addStockLevel($stockLevel);
     56 
     57         $this->getContainer()->get('doctrine.orm.default_entity_manager')->flush();
     58 
     59         $iriCoverter = $this->getContainer()->get('api.iri_converter');
     60         $iri = $iriCoverter->getIriFromItem($part1);
     61 
     62         $client->request('GET', $iri);
     63 
     64         $response = $client->getResponse()->getContent();
     65         $responseObj = json_decode($response, true);
     66         $responseObj['stockLevels'] = [];
     67 
     68         $client->request('PUT', $iri, [], [], [], json_encode($responseObj));
     69 
     70         $this->assertEquals(200, $client->getResponse()->getStatusCode());
     71 
     72         $this->getContainer()->get('doctrine.orm.default_entity_manager')->refresh($part1);
     73         $this->assertEquals(1, count($part1->getStockLevels()));
     74     }
     75 }