name = $name; $this->namespace = $namespace; $this->default_namespace = $default_namespace; $this->is_valid = $is_valid; $this->expected_fullname = $expected_fullname; } function __toString() { return var_export($this, true); } } class NameTest extends PHPUnit_Framework_TestCase { function fullname_provider() { $examples = array(new NameExample('foo', null, null, true, 'foo'), new NameExample('foo', 'bar', null, true, 'bar.foo'), new NameExample('bar.foo', 'baz', null, true, 'bar.foo'), new NameExample('_bar.foo', 'baz', null, true, '_bar.foo'), new NameExample('bar._foo', 'baz', null, true, 'bar._foo'), new NameExample('3bar.foo', 'baz', null, false), new NameExample('bar.3foo', 'baz', null, false), new NameExample('b4r.foo', 'baz', null, true, 'b4r.foo'), new NameExample('bar.f0o', 'baz', null, true, 'bar.f0o'), new NameExample(' .foo', 'baz', null, false), new NameExample('bar. foo', 'baz', null, false), new NameExample('bar. ', 'baz', null, false) ); $exes = array(); foreach ($examples as $ex) $exes []= array($ex); return $exes; } /** * @dataProvider fullname_provider */ function test_fullname($ex) { try { $name = new AvroName($ex->name, $ex->namespace, $ex->default_namespace); $this->assertTrue($ex->is_valid); $this->assertEquals($ex->expected_fullname, $name->fullname()); } catch (AvroSchemaParseException $e) { $this->assertFalse($ex->is_valid, sprintf("%s:\n%s", $ex, $e->getMessage())); } } function name_provider() { return array(array('a', true), array('_', true), array('1a', false), array('', false), array(null, false), array(' ', false), array('Cons', true)); } /** * @dataProvider name_provider */ function test_name($name, $is_well_formed) { $this->assertEquals(AvroName::is_well_formed_name($name), $is_well_formed, $name); } }