Commit 90965a2d authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Le champ TYPE pour les organisations (Connecteur REST) permet la valeur NULL

parent 7615889f
Loading
Loading
Loading
Loading
Loading
+2 −2
Changes for module/Oscar/src/Oscar/Factory/JsonToOrganization.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -26,9 +26,9 @@ class JsonToOrganization extends JsonToObject implements IJsonToOrganisation

    private ?array $types;

    protected function getTypeObj(string $typeLabel): ?OrganizationType
    public function getTypeObj(?string $typeLabel = null): ?OrganizationType
    {
        if (is_array($this->types) && array_key_exists($typeLabel, $this->types)) {
        if (!is_null($typeLabel) && is_array($this->types) && array_key_exists($typeLabel, $this->types)) {
            return $this->types[$typeLabel];
        }
        return null;
+20 −0
Changes for tests/Oscar/Connector/JsonToOrganizationTest.php: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php
use PHPUnit\Framework\TestCase;

class JsonToOrganizationTest extends TestCase
{
    public function testType()
    {
        $type = new \Oscar\Entity\OrganizationType();
        $type->setLabel("Type d'organisation");
        $types = ["foo" => $type];
        $json = new \Oscar\Factory\JsonToOrganization($types);

        $this->assertNull($json->getTypeObj(null), 'Les types NULL retournent NULL');
        $this->assertNull($json->getTypeObj(""), 'Les types "chaîne vide" retournent NULL');
        $this->assertNull($json->getTypeObj("nexistepas"), 'Les types non référencés retournent NULL');

        $extractedType = $json->getTypeObj("foo");
        $this->assertEquals($extractedType, $type);
    }
}