<?php namespace org\example\imports;
use lang\Reflection;
enum Sources: string {
case FromEmpty = '__EMPTY__';
case FromCampus = 'CAMPUS';
/** Returns source kind */
public function kind(): string { return $this->value; }
/** Creates a new source instance with given arguments */
public function newInstance(mixed... $args): Source {
return Reflection::of(__NAMESPACE__)->type($this->name)->newInstance(...$args);
}
}
Usage:
<?php namespace org\example\imports\unittest;
use org\example\imports\{Source, Sources};
use unittest\{Assert, Test};
class SourcesTest {
#[Test]
public function create_instance() {
Assert::instance(Source::class, Sources::FromEmpty->newInstance());
}
}
When compiling the unittest, Sources::FromEmpty is not detected as an enum constant!
Declaration (shortened for brevitiy):
Usage:
When compiling the unittest,
Sources::FromEmpty
is not detected as an enum constant!