-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support null,int,float defaults * support empty string default
- Loading branch information
Showing
3 changed files
with
126 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpKafka\PhpAvroSchemaGenerator\Tests\Integration\Parser; | ||
|
||
use PhpKafka\PhpAvroSchemaGenerator\Parser\ClassParser; | ||
use PhpKafka\PhpAvroSchemaGenerator\Parser\ClassPropertyParser; | ||
use PhpKafka\PhpAvroSchemaGenerator\Parser\DocCommentParser; | ||
use PhpKafka\PhpAvroSchemaGenerator\PhpClass\PhpClassPropertyInterface; | ||
use PhpParser\ParserFactory; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers PhpKafka\PhpAvroSchemaGenerator\Parser\ClassPropertyParser | ||
*/ | ||
class ClassPropertyParserTest extends TestCase | ||
{ | ||
public function testNullDefaultProperty(): void | ||
{ | ||
$propertyParser = new ClassPropertyParser(new DocCommentParser()); | ||
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser); | ||
$parser->setCode(' | ||
<?php | ||
class foo { | ||
/** | ||
* @avro-default null | ||
*/ | ||
public $bla; | ||
} | ||
'); | ||
$properties = $parser->getProperties(); | ||
self::assertEquals(1, count($properties)); | ||
self::assertNull($properties[0]->getPropertyDefault()); | ||
} | ||
|
||
public function testIntDefaultProperty(): void | ||
{ | ||
$propertyParser = new ClassPropertyParser(new DocCommentParser()); | ||
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser); | ||
$parser->setCode(' | ||
<?php | ||
class foo { | ||
/** | ||
* @avro-default 1 | ||
*/ | ||
public $bla; | ||
} | ||
'); | ||
$properties = $parser->getProperties(); | ||
self::assertEquals(1, count($properties)); | ||
self::assertIsInt($properties[0]->getPropertyDefault()); | ||
} | ||
|
||
public function testFloatDefaultProperty(): void | ||
{ | ||
$propertyParser = new ClassPropertyParser(new DocCommentParser()); | ||
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser); | ||
$parser->setCode(' | ||
<?php | ||
class foo { | ||
/** | ||
* @avro-default 1.2 | ||
*/ | ||
public $bla; | ||
} | ||
'); | ||
$properties = $parser->getProperties(); | ||
self::assertEquals(1, count($properties)); | ||
self::assertIsFloat($properties[0]->getPropertyDefault()); | ||
} | ||
|
||
public function testEmptyStringDefaultProperty(): void | ||
{ | ||
$propertyParser = new ClassPropertyParser(new DocCommentParser()); | ||
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser); | ||
$parser->setCode(' | ||
<?php | ||
class foo { | ||
/** | ||
* @avro-default empty-string-default | ||
*/ | ||
public $bla; | ||
} | ||
'); | ||
$properties = $parser->getProperties(); | ||
self::assertEquals(1, count($properties)); | ||
self::assertEquals('', $properties[0]->getPropertyDefault()); | ||
} | ||
} |