createAdminClient(); $seed = $this->seedSupplier('Virement No Bank'); $response = $client->request('PATCH', '/api/suppliers/'.$seed->getId(), [ 'headers' => ['Content-Type' => self::MERGE, 'Accept' => self::LD], 'json' => ['paymentType' => '/api/payment_types/'.$this->paymentType('VIREMENT')->getId()], ]); self::assertResponseStatusCodeSame(422); self::assertArrayHasKey('bank', $this->violationsByPath($response->toArray(false))); } public function testVirementWithBankReturns200(): void { $client = $this->createAdminClient(); $seed = $this->seedSupplier('Virement With Bank'); $client->request('PATCH', '/api/suppliers/'.$seed->getId(), [ 'headers' => ['Content-Type' => self::MERGE], 'json' => [ 'paymentType' => '/api/payment_types/'.$this->paymentType('VIREMENT')->getId(), 'bank' => '/api/banks/'.$this->bank('SG')->getId(), ], ]); self::assertResponseStatusCodeSame(200); } // === RG-2.08 : LCR impose au moins un RIB === public function testLcrWithoutRibReturns422OnRibsPath(): void { $client = $this->createAdminClient(); $seed = $this->seedSupplier('Lcr No Rib'); $response = $client->request('PATCH', '/api/suppliers/'.$seed->getId(), [ 'headers' => ['Content-Type' => self::MERGE, 'Accept' => self::LD], 'json' => ['paymentType' => '/api/payment_types/'.$this->paymentType('LCR')->getId()], ]); self::assertResponseStatusCodeSame(422); self::assertArrayHasKey('ribs', $this->violationsByPath($response->toArray(false))); } public function testLcrWithRibReturns200(): void { $client = $this->createAdminClient(); $seed = $this->seedSupplier('Lcr With Rib'); $this->addRib($seed); $client->request('PATCH', '/api/suppliers/'.$seed->getId(), [ 'headers' => ['Content-Type' => self::MERGE], 'json' => ['paymentType' => '/api/payment_types/'.$this->paymentType('LCR')->getId()], ]); self::assertResponseStatusCodeSame(200); } /** * @param array $body * * @return array */ private function violationsByPath(array $body): array { $byPath = []; foreach ($body['violations'] ?? [] as $v) { $byPath[$v['propertyPath']] = $v['message']; } return $byPath; } }