diff --git a/composer.json b/composer.json index 262d1722..672e1b69 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,6 @@ "psr-4": {"Zenstruck\\Foundry\\": "src/"}, "files": [ "src/functions.php", - "src/deprecations.php", "src/Persistence/functions.php" ] }, diff --git a/src/Bundle/DependencyInjection/ZenstruckFoundryExtension.php b/src/Bundle/DependencyInjection/ZenstruckFoundryExtension.php index d63ca514..3fa8d01d 100644 --- a/src/Bundle/DependencyInjection/ZenstruckFoundryExtension.php +++ b/src/Bundle/DependencyInjection/ZenstruckFoundryExtension.php @@ -127,7 +127,7 @@ private function configureDatabaseResetter(array $config, ContainerBuilder $cont $legacyConfig = $config['database_resetter']; if (false === $legacyConfig['enabled']) { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Disabling database reset via bundle configuration is deprecated and will be removed in 2.0. Instead you should not use "%s" trait in your test.', ResetDatabase::class)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Disabling database reset via bundle configuration is deprecated and will be removed in 2.0. Instead you should not use "%s" trait in your test.', ResetDatabase::class); $configurationDefinition->addMethodCall('disableDatabaseReset'); } diff --git a/src/Bundle/Maker/Factory/NoPersistenceObjectsAutoCompleter.php b/src/Bundle/Maker/Factory/NoPersistenceObjectsAutoCompleter.php index c5469823..984ffba0 100644 --- a/src/Bundle/Maker/Factory/NoPersistenceObjectsAutoCompleter.php +++ b/src/Bundle/Maker/Factory/NoPersistenceObjectsAutoCompleter.php @@ -34,7 +34,7 @@ public function getAutocompleteValues(): array $class = $this->toPSR4($rootPath, $phpFile, $namespacePrefix); - if (\in_array($class, ['Zenstruck\Foundry\Proxy', 'Zenstruck\Foundry\RepositoryProxy'])) { + if (\in_array($class, ['Zenstruck\Foundry\Proxy', 'Zenstruck\Foundry\RepositoryProxy', 'Zenstruck\Foundry\RepositoryAssertions'])) { // do not load legacy Proxy: prevents deprecations in tests. continue; } diff --git a/src/Factory.php b/src/Factory.php index beba9ef6..b6b00267 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -99,7 +99,7 @@ public function create( bool $noProxy = false ): object { if (2 === \count(\func_get_args()) && !\str_starts_with(\debug_backtrace(options: \DEBUG_BACKTRACE_IGNORE_ARGS, limit: 1)[0]['class'] ?? '', 'Zenstruck\Foundry')) { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Parameter "$noProxy" of method "%s()" is deprecated and will be removed in Foundry 2.0.', __METHOD__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Parameter "$noProxy" of method "%s()" is deprecated and will be removed in Foundry 2.0.', __METHOD__); } // merge the factory attribute set with the passed attributes @@ -203,7 +203,7 @@ final public function many(int $min, ?int $max = null): FactoryCollection final public function sequence(iterable|callable $sequence): FactoryCollection { if (\is_callable($sequence)) { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Passing a callable to method "%s()" is deprecated and will be removed in 2.0.', __METHOD__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Passing a callable to method "%s()" is deprecated and will be removed in 2.0.', __METHOD__); $sequence = $sequence(); } @@ -231,7 +231,7 @@ public function withoutPersisting(): self */ final public function withAttributes($attributes = []): self { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in 2.0. Use "%s::with()" instead.', __METHOD__, self::class)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in 2.0. Use "%s::with()" instead.', __METHOD__, self::class); return $this->with($attributes); } @@ -352,7 +352,7 @@ final public static function faker(): Faker\Generator */ final public static function delayFlush(callable $callback): mixed { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in Foundry 2.0. Use "Zenstruck\Foundry\Persistence\flush_after()" instead.', __METHOD__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in Foundry 2.0. Use "Zenstruck\Foundry\Persistence\flush_after()" instead.', __METHOD__); return self::configuration()->delayFlush($callback); } diff --git a/src/FactoryCollection.php b/src/FactoryCollection.php index fafacade..33646a83 100644 --- a/src/FactoryCollection.php +++ b/src/FactoryCollection.php @@ -76,7 +76,7 @@ public function create( bool $noProxy = false ): array { if (2 === \count(\func_get_args()) && !\str_starts_with(\debug_backtrace(options: \DEBUG_BACKTRACE_IGNORE_ARGS, limit: 1)[0]['class'] ?? '', 'Zenstruck\Foundry')) { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Parameter "$noProxy" of method "%s()" is deprecated and will be removed in Foundry 2.0.', __METHOD__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Parameter "$noProxy" of method "%s()" is deprecated and will be removed in Foundry 2.0.', __METHOD__); } $objects = []; diff --git a/src/Instantiator.php b/src/Instantiator.php index d005c158..f61d6084 100644 --- a/src/Instantiator.php +++ b/src/Instantiator.php @@ -41,7 +41,7 @@ final class Instantiator public function __construct(bool $calledInternally = false) { if (!$calledInternally) { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('%1$s constructor will be private in Foundry 2.0. Use either "%1$s::withConstructor()" or "%1$s::withoutConstructor()"', self::class)); + trigger_deprecation('zenstruck\foundry', '1.37.0', '%1$s constructor will be private in Foundry 2.0. Use either "%1$s::withConstructor()" or "%1$s::withoutConstructor()"', self::class); } } diff --git a/src/ModelFactory.php b/src/ModelFactory.php index 8b7ec423..c9026219 100644 --- a/src/ModelFactory.php +++ b/src/ModelFactory.php @@ -34,18 +34,16 @@ public function __construct() trigger_deprecation( 'zenstruck\foundry', '1.37.0', - \sprintf( - <<with($attributes); } diff --git a/src/Persistence/PersistentProxyObjectFactory.php b/src/Persistence/PersistentProxyObjectFactory.php index 18a818bd..58245351 100644 --- a/src/Persistence/PersistentProxyObjectFactory.php +++ b/src/Persistence/PersistentProxyObjectFactory.php @@ -44,7 +44,9 @@ final public static function new(array|callable|string $defaultAttributes = [], if ((new \ReflectionClass(static::class()))->isFinal()) { trigger_deprecation( 'zenstruck\foundry', '1.37.0', - \sprintf('Using a proxy factory with a final class is deprecated and will throw an error in Foundry 2.0. Use "%s" instead, or unfinalize "%s" class.', self::class, static::class()) + 'Using a proxy factory with a final class is deprecated and will throw an error in Foundry 2.0. Use "%s" instead, or unfinalize "%s" class.', + self::class, + static::class() ); } @@ -63,7 +65,7 @@ final public function create( bool $noProxy = false ): object { if (2 === \count(\func_get_args()) && !\str_starts_with(\debug_backtrace(options: \DEBUG_BACKTRACE_IGNORE_ARGS, limit: 1)[0]['class'] ?? '', 'Zenstruck\Foundry')) { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Parameter "$noProxy" of method "%s()" is deprecated and will be removed in Foundry 2.0.', __METHOD__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Parameter "$noProxy" of method "%s()" is deprecated and will be removed in Foundry 2.0.', __METHOD__); } return Factory::create($attributes, noProxy: false); diff --git a/src/Persistence/Proxy.php b/src/Persistence/Proxy.php index 25ffc4e4..85ab277c 100644 --- a/src/Persistence/Proxy.php +++ b/src/Persistence/Proxy.php @@ -51,4 +51,73 @@ public function _disableAutoRefresh(): static; * @param callable $callback (object|Proxy $object): void */ public function _withoutAutoRefresh(callable $callback): static; + + /** + * @return TProxiedObject + * + * @deprecated Use method "_real()" instead + */ + public function object(): object; + + /** + * @deprecated Use method "_save()" instead + */ + public function save(): static; + + /** + * @deprecated Use method "_delete()" instead + */ + public function remove(): static; + + /** + * @deprecated Use method "_refresh()" instead + */ + public function refresh(): static; + + /** + * @deprecated Use method "_set()" instead + */ + public function forceSet(string $property, mixed $value): static; + + /** + * @deprecated without replacement + */ + public function forceSetAll(array $properties): static; + + /** + * @deprecated Use method "_get()" instead + */ + public function get(string $property): mixed; + + /** + * @deprecated Use method "_repository()" instead + */ + public function repository(): RepositoryDecorator; + + /** + * @deprecated Use method "_enableAutoRefresh()" instead + */ + public function enableAutoRefresh(): static; + + /** + * @deprecated Use method "_disableAutoRefresh()" instead + */ + public function disableAutoRefresh(): static; + + /** + * @param callable $callback (object|Proxy $object): void + * + * @deprecated Use method "_withoutAutoRefresh()" instead + */ + public function withoutAutoRefresh(callable $callback): static; + + /** + * @deprecated without replacement + */ + public function assertPersisted(string $message = '{entity} is not persisted.'): self; + + /** + * @deprecated without replacement + */ + public function assertNotPersisted(string $message = '{entity} is persisted but it should not be.'): self; } diff --git a/src/Persistence/RepositoryAssertions.php b/src/Persistence/RepositoryAssertions.php index 3eb13724..5f744e87 100644 --- a/src/Persistence/RepositoryAssertions.php +++ b/src/Persistence/RepositoryAssertions.php @@ -136,3 +136,5 @@ public function notExists($criteria, string $message = 'Expected {entity} to not return $this; } } + +class_exists(\Zenstruck\Foundry\RepositoryAssertions::class); diff --git a/src/Persistence/RepositoryDecorator.php b/src/Persistence/RepositoryDecorator.php index 2d6ff5c4..788f3962 100644 --- a/src/Persistence/RepositoryDecorator.php +++ b/src/Persistence/RepositoryDecorator.php @@ -457,3 +457,5 @@ private function getObjectManager(): ObjectManager return Factory::configuration()->objectManagerFor($this->getClassName()); } } + +class_exists(\Zenstruck\Foundry\RepositoryProxy::class); diff --git a/src/Proxy.php b/src/Proxy.php index 60fb707b..b58d408a 100644 --- a/src/Proxy.php +++ b/src/Proxy.php @@ -54,7 +54,9 @@ public function __construct( if ((new \ReflectionClass($object::class))->isFinal()) { trigger_deprecation( 'zenstruck\foundry', '1.37.0', - \sprintf('Using a proxy factory with a final class is deprecated and will throw an error in Foundry 2.0. Use "%s" instead, or unfinalize "%s" class.', PersistentProxyObjectFactory::class, $object::class) + 'Using a proxy factory with a final class is deprecated and will throw an error in Foundry 2.0. Use "%s" instead, or unfinalize "%s" class.', + PersistentProxyObjectFactory::class, + $object::class ); } @@ -114,12 +116,12 @@ public static function createFromPersisted(object $object): self } /** - * @deprecated + * @deprecated without replacement */ public function isPersisted(bool $calledInternally = false): bool { if (!$calledInternally) { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in 2.0 without replacement.', __METHOD__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in 2.0 without replacement.', __METHOD__); } return $this->persisted; @@ -128,11 +130,11 @@ public function isPersisted(bool $calledInternally = false): bool /** * @return TProxiedObject * - * @deprecated + * @deprecated Use method "_real()" instead */ public function object(): object { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_real()" instead.', __METHOD__, self::class)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_real()" instead.', __METHOD__, self::class); return $this->_real(); } @@ -163,11 +165,11 @@ public function _real(): object } /** - * @deprecated + * @deprecated Use method "_save()" instead */ public function save(): static { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_save()" instead.', __METHOD__, self::class)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_save()" instead.', __METHOD__, self::class); return $this->_save(); } @@ -186,11 +188,11 @@ public function _save(): static } /** - * @deprecated + * @deprecated Use method "_delete()" instead */ public function remove(): static { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_delete()" instead.', __METHOD__, self::class)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_delete()" instead.', __METHOD__, self::class); return $this->_delete(); } @@ -206,11 +208,11 @@ public function _delete(): static } /** - * @deprecated + * @deprecated Use method "_refresh()" instead */ public function refresh(): static { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_refresh()" instead.', __METHOD__, self::class)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_refresh()" instead.', __METHOD__, self::class); return $this->_refresh(); } @@ -241,11 +243,11 @@ public function _refresh(): static } /** - * @deprecated + * @deprecated Use method "_set()" instead */ public function forceSet(string $property, mixed $value): static { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_set()" instead.', __METHOD__, self::class)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_set()" instead.', __METHOD__, self::class); return $this->_set($property, $value); } @@ -260,11 +262,11 @@ public function _set(string $property, mixed $value): static } /** - * @deprecated + * @deprecated without replacement */ public function forceSetAll(array $properties): static { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in 2.0 without replacement.', __METHOD__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in 2.0 without replacement.', __METHOD__); $object = $this->_real(); @@ -276,11 +278,11 @@ public function forceSetAll(array $properties): static } /** - * @deprecated + * @deprecated Use method "_get()" instead */ public function get(string $property): mixed { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_get()" instead.', __METHOD__, self::class)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_get()" instead.', __METHOD__, self::class); return $this->_get($property); } @@ -291,11 +293,11 @@ public function _get(string $property): mixed } /** - * @deprecated + * @deprecated Use method "_repository()" instead */ public function repository(): RepositoryDecorator { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_repository()" instead.', __METHOD__, self::class)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_repository()" instead.', __METHOD__, self::class); return $this->_repository(); } @@ -306,11 +308,11 @@ public function _repository(): RepositoryDecorator } /** - * @deprecated + * @deprecated Use method "_enableAutoRefresh()" instead */ public function enableAutoRefresh(): static { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_enableAutoRefresh()" instead.', __METHOD__, self::class)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_enableAutoRefresh()" instead.', __METHOD__, self::class); return $this->_enableAutoRefresh(); } @@ -327,11 +329,11 @@ public function _enableAutoRefresh(): static } /** - * @deprecated + * @deprecated Use method "_disableAutoRefresh()" instead */ public function disableAutoRefresh(): static { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_disableAutoRefresh()" instead.', __METHOD__, self::class)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_disableAutoRefresh()" instead.', __METHOD__, self::class); return $this->_disableAutoRefresh(); } @@ -346,11 +348,11 @@ public function _disableAutoRefresh(): static /** * @param callable $callback (object|Proxy $object): void * - * @deprecated + * @deprecated Use method "_withoutAutoRefresh()" instead */ public function withoutAutoRefresh(callable $callback): static { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_withoutAutoRefresh()" instead.', __METHOD__, self::class)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in 2.0. Use "%s::_withoutAutoRefresh()" instead.', __METHOD__, self::class); return $this->_withoutAutoRefresh($callback); } @@ -368,11 +370,11 @@ public function _withoutAutoRefresh(callable $callback): static } /** - * @deprecated + * @deprecated without replacement */ public function assertPersisted(string $message = '{entity} is not persisted.'): self { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in 2.0 without replacement.', __METHOD__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in 2.0 without replacement.', __METHOD__); Assert::that($this->fetchObject())->isNotEmpty($message, ['entity' => $this->class]); @@ -380,11 +382,11 @@ public function assertPersisted(string $message = '{entity} is not persisted.'): } /** - * @deprecated + * @deprecated without replacement */ public function assertNotPersisted(string $message = '{entity} is persisted but it should not be.'): self { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in 2.0 without replacement.', __METHOD__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in 2.0 without replacement.', __METHOD__); Assert::that($this->fetchObject())->isEmpty($message, ['entity' => $this->class]); diff --git a/src/RepositoryAssertions.php b/src/RepositoryAssertions.php index 9e92ebe7..36d2e52f 100644 --- a/src/RepositoryAssertions.php +++ b/src/RepositoryAssertions.php @@ -13,7 +13,17 @@ use Zenstruck\Foundry\Persistence\RepositoryAssertions as NewRepositoryAssertions; -trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Class "%s" is deprecated and will be removed in version 2.0. Use "%s" instead.', RepositoryAssertions::class, NewRepositoryAssertions::class)); +if (!class_exists(NewRepositoryAssertions::class, false)) { + trigger_deprecation( + 'zenstruck\foundry', + '1.37.0', + 'Class "%s" is deprecated and will be removed in version 2.0. Use "%s" instead.', + RepositoryAssertions::class, + NewRepositoryAssertions::class + ); +} + +\class_alias(NewRepositoryAssertions::class, RepositoryAssertions::class); if (false) { /** diff --git a/src/RepositoryProxy.php b/src/RepositoryProxy.php index 623034f9..0f136cdb 100644 --- a/src/RepositoryProxy.php +++ b/src/RepositoryProxy.php @@ -14,11 +14,17 @@ use Doctrine\ORM\EntityRepository; use Zenstruck\Foundry\Persistence\RepositoryDecorator; -trigger_deprecation( - 'zenstruck\foundry', - '1.37.0', - \sprintf('Class "%s" is deprecated and will be removed in version 2.0. Use "%s" instead.', RepositoryProxy::class, RepositoryDecorator::class) -); +if (!class_exists(RepositoryDecorator::class, false)) { + trigger_deprecation( + 'zenstruck\foundry', + '1.37.0', + 'Class "%s" is deprecated and will be removed in version 2.0. Use "%s" instead.', + RepositoryProxy::class, + RepositoryDecorator::class + ); +} + +\class_alias(RepositoryDecorator::class, RepositoryProxy::class); if (false) { /** diff --git a/src/Test/Factories.php b/src/Test/Factories.php index bf13ac90..191b4393 100644 --- a/src/Test/Factories.php +++ b/src/Test/Factories.php @@ -79,7 +79,7 @@ public static function _tearDownFactories(): void */ public function disablePersist(): void { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in Foundry 2.0. Use "Zenstruck\Foundry\Persistence\disable_persisting()" instead.', __METHOD__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in Foundry 2.0. Use "Zenstruck\Foundry\Persistence\disable_persisting()" instead.', __METHOD__); disable_persisting(); } @@ -89,7 +89,7 @@ public function disablePersist(): void */ public function enablePersist(): void { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in Foundry 2.0. Use "Zenstruck\Foundry\Persistence\enable_persisting()" instead.', __METHOD__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in Foundry 2.0. Use "Zenstruck\Foundry\Persistence\enable_persisting()" instead.', __METHOD__); enable_persisting(); } diff --git a/src/Test/TestState.php b/src/Test/TestState.php index 2e3b94e5..5c54f632 100644 --- a/src/Test/TestState.php +++ b/src/Test/TestState.php @@ -41,7 +41,7 @@ final class TestState */ public static function setInstantiator(callable $instantiator): void { - trigger_deprecation('zenstruck/foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in Foundry 2.0. Use "%s::configure()" instead.', __METHOD__, UnitTestConfig::class)); + trigger_deprecation('zenstruck/foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in Foundry 2.0. Use "%s::configure()" instead.', __METHOD__, UnitTestConfig::class); self::$instantiator = $instantiator; } @@ -51,7 +51,7 @@ public static function setInstantiator(callable $instantiator): void */ public static function setFaker(Faker\Generator $faker): void { - trigger_deprecation('zenstruck/foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in Foundry 2.0. Use "%s::configure()" instead.', __METHOD__, UnitTestConfig::class)); + trigger_deprecation('zenstruck/foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in Foundry 2.0. Use "%s::configure()" instead.', __METHOD__, UnitTestConfig::class); self::$faker = $faker; } @@ -61,7 +61,7 @@ public static function setFaker(Faker\Generator $faker): void */ public static function enableDefaultProxyAutoRefresh(): void { - trigger_deprecation('zenstruck/foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in Foundry 2.0 without replacement.', __METHOD__)); + trigger_deprecation('zenstruck/foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in Foundry 2.0 without replacement.', __METHOD__); self::$defaultProxyAutoRefresh = true; } @@ -71,7 +71,7 @@ public static function enableDefaultProxyAutoRefresh(): void */ public static function disableDefaultProxyAutoRefresh(): void { - trigger_deprecation('zenstruck/foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in Foundry 2.0 without replacement.', __METHOD__)); + trigger_deprecation('zenstruck/foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in Foundry 2.0 without replacement.', __METHOD__); self::$defaultProxyAutoRefresh = false; } @@ -81,7 +81,7 @@ public static function disableDefaultProxyAutoRefresh(): void */ public static function alwaysAutoRefreshProxies(): void { - trigger_deprecation('zenstruck/foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in Foundry 2.0 without replacement.', __METHOD__)); + trigger_deprecation('zenstruck/foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in Foundry 2.0 without replacement.', __METHOD__); self::enableDefaultProxyAutoRefresh(); } @@ -150,7 +150,7 @@ public static function shutdownFoundry(): void */ public static function bootFactory(Configuration $configuration): Configuration { - trigger_deprecation('zenstruck/foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in Foundry 2.0 without replacement.', __METHOD__)); + trigger_deprecation('zenstruck/foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in Foundry 2.0 without replacement.', __METHOD__); self::bootFoundry($configuration); @@ -225,7 +225,7 @@ public static function flushGlobalState(?GlobalStateRegistry $globalStateRegistr */ public static function configure(?Instantiator $instantiator = null, ?Faker\Generator $faker = null): void { - trigger_deprecation('zenstruck/foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in Foundry 2.0. Use "%s::configure()" instead.', __METHOD__, UnitTestConfig::class)); + trigger_deprecation('zenstruck/foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in Foundry 2.0. Use "%s::configure()" instead.', __METHOD__, UnitTestConfig::class); self::$instantiator = $instantiator; self::$faker = $faker; diff --git a/src/deprecations.php b/src/deprecations.php deleted file mode 100644 index a37e20a3..00000000 --- a/src/deprecations.php +++ /dev/null @@ -1,16 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Zenstruck\Foundry\Persistence\RepositoryDecorator; -use Zenstruck\Foundry\RepositoryProxy; - -\class_alias(\Zenstruck\Foundry\Persistence\RepositoryAssertions::class, \Zenstruck\Foundry\RepositoryAssertions::class); -\class_alias(RepositoryDecorator::class, RepositoryProxy::class); diff --git a/src/functions.php b/src/functions.php index 4a778d56..610244bc 100644 --- a/src/functions.php +++ b/src/functions.php @@ -49,7 +49,7 @@ function factory(string $class, array|callable $defaultAttributes = []): Anonymo */ function anonymous(string $class, array|callable $defaultAttributes = []): Factory { - trigger_deprecation('zenstruck\foundry', '1.37', \sprintf('Usage of "%s()" function is deprecated and will be removed in 2.0. Use the "Zenstruck\Foundry\Persistence\proxy_factory()" function instead.', __FUNCTION__)); + trigger_deprecation('zenstruck\foundry', '1.37', 'Usage of "%s()" function is deprecated and will be removed in 2.0. Use the "Zenstruck\Foundry\Persistence\proxy_factory()" function instead.', __FUNCTION__); return proxy_factory($class, $defaultAttributes); } @@ -67,7 +67,7 @@ function anonymous(string $class, array|callable $defaultAttributes = []): Facto */ function create(string $class, array|callable $attributes = []): Proxy { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Function "%s()" is deprecated and will be removed in Foundry 2.0. Use "Zenstruck\Foundry\Persistence\persist_proxy()" instead.', __FUNCTION__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Function "%s()" is deprecated and will be removed in Foundry 2.0. Use "Zenstruck\Foundry\Persistence\persist_proxy()" instead.', __FUNCTION__); return persist_proxy($class, $attributes); } @@ -85,7 +85,7 @@ function create(string $class, array|callable $attributes = []): Proxy */ function create_many(int $number, string $class, array|callable $attributes = []): array { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Function "%s()" is deprecated and will be removed in Foundry 2.0 without replacement.', __FUNCTION__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Function "%s()" is deprecated and will be removed in Foundry 2.0 without replacement.', __FUNCTION__); return proxy_factory($class)->many($number)->create($attributes); } @@ -103,7 +103,7 @@ function create_many(int $number, string $class, array|callable $attributes = [] */ function instantiate(string $class, array|callable $attributes = []): Proxy { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Function "%s()" is deprecated and will be removed in Foundry 2.0. Use "%s::object()" instead.', __FUNCTION__, __NAMESPACE__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Function "%s()" is deprecated and will be removed in Foundry 2.0. Use "%s::object()" instead.', __FUNCTION__, __NAMESPACE__); return new ProxyObject(object($class, $attributes)); } @@ -134,7 +134,7 @@ function object(string $class, array|callable $attributes = []): object */ function instantiate_many(int $number, string $class, array|callable $attributes = []): array { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Function "%s()" is deprecated and will be removed in Foundry 2.0 without replacement.', __FUNCTION__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Function "%s()" is deprecated and will be removed in Foundry 2.0 without replacement.', __FUNCTION__); return proxy_factory($class)->withoutPersisting()->many($number)->create($attributes); } @@ -152,10 +152,10 @@ function instantiate_many(int $number, string $class, array|callable $attributes */ function repository(object|string $objectOrClass): RepositoryDecorator { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Function "%s()" is deprecated and will be removed in Foundry 2.0. Use "Zenstruck\Foundry\Persistence\repository()" instead.', __FUNCTION__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Function "%s()" is deprecated and will be removed in Foundry 2.0. Use "Zenstruck\Foundry\Persistence\repository()" instead.', __FUNCTION__); if (\is_object($objectOrClass)) { - trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Passing objects to "%s()" is deprecated and will be removed in Foundry 2.0. Pass directly class-string instead.', __FUNCTION__)); + trigger_deprecation('zenstruck\foundry', '1.37.0', 'Passing objects to "%s()" is deprecated and will be removed in Foundry 2.0. Pass directly class-string instead.', __FUNCTION__); $objectOrClass = $objectOrClass::class; } diff --git a/tests/Functional/RepositoryDecoratorTest.php b/tests/Functional/RepositoryDecoratorTest.php index 6a65b3e8..c15bfb6e 100644 --- a/tests/Functional/RepositoryDecoratorTest.php +++ b/tests/Functional/RepositoryDecoratorTest.php @@ -348,11 +348,11 @@ public function can_use_get_count(): void */ public function can_use_new_class_as_legacy_one(): void { - self::assertTrue($this->categoryFactoryClass()::repository() instanceof \Zenstruck\Foundry\RepositoryProxy); self::assertTrue($this->categoryFactoryClass()::repository() instanceof \Zenstruck\Foundry\Persistence\RepositoryDecorator); + self::assertTrue($this->categoryFactoryClass()::repository() instanceof \Zenstruck\Foundry\RepositoryProxy); - self::assertTrue($this->categoryFactoryClass()::assert() instanceof \Zenstruck\Foundry\RepositoryAssertions); self::assertTrue($this->categoryFactoryClass()::assert() instanceof \Zenstruck\Foundry\Persistence\RepositoryAssertions); + self::assertTrue($this->categoryFactoryClass()::assert() instanceof \Zenstruck\Foundry\RepositoryAssertions); } abstract protected function categoryClass(): string;