Thomas Hansen efccc01911
[PHP] BUGFIX: model_generic: fix missing setOpenAPInullablesSetToNull method (#13499)
* [PHP] Bugfix - model_generic.mustache: missing setter for openAPINullabelsSetToNull (which is invoked in the property setters)

* [AUTOGENERATED] update samples

* [PHP] Added test for nullable fields
2022-09-26 17:20:51 +08:00

39 lines
1.1 KiB
PHP

<?php
namespace OpenAPI\Client;
use InvalidArgumentException;
use OpenAPI\Client\Model\Name;
use OpenAPI\Client\Model\NullableClass;
use PHPUnit\Framework\TestCase;
/**
* class NullableTest
*
* @package OpenAPI\Client
*/
class NullableTest extends TestCase
{
public function testNotNullableException(): void
{
$name = new Name();
$name->setName(1);
$this->assertEquals(1, $name->getName(), 'Non-nullable property can be set and retains its value');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('non-nullable name cannot be null');
$name->setName(null);
}
public function testNullableobject(): void
{
$nullable = new NullableClass();
$nullable->setIntegerProp(null);
$this->assertNull($nullable->getIntegerProp(), 'Nullable property can be set to null retains its value');
$nullable->setIntegerProp(1);
$this->assertEquals(1, $nullable->getIntegerProp(), 'Nullable property can be set and retains its value');
}
}