foundry icon indicating copy to clipboard operation
foundry copied to clipboard

refactor: add a BC layer for 2.x

Open nikophil opened this issue 2 years ago • 2 comments

  • [ ] Doc update
  • [x] Bundle configuration
    • [x] Remove auto_refresh_proxies https://github.com/zenstruck/foundry/pull/524
    • [x] ~Remove make_factory~ (I don't think we should do this)
    • [x] without_constructor => use_constructor
    • [x] remove database_resetter.enabled
    • [x] move database_resetter.orm|odm to root
  • [x] ~Object Instantiator split into Instantiator/Hydrator~ (actually nothing to do here)
  • [x] Zenstruck\Foundry\Factory
    • [x] withAttributes() -> with()
    • [x] ~__construct() removed~ :warning: we must keep an empty __construct() in Factory
    • [x] Factory::sequence() used to accept iterable|callable now it only accepts iterable
  • [x] Zenstruck\Foundry\ModelFactory -> Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory
    • [x] protected function getDefaults(): array -> protected function defaults(): array|callable
    • [x] protected static function getClass(): string -> public static function class(): string
    • [x] protected function initialize() -> protected function initialize(): static
    • [x] addState() -> with()
  • [x] Zenstruck\Foundry\Proxy -> Zenstruck\Foundry\Persistence\Proxy
    • [x] no longer implements \Stringable
    • [x] isPersisted() removed
    • [x] object() -> _real()
    • [x] save() -> _save()
    • [x] remove() -> _delete()
    • [x] refresh() -> _refresh()
    • [x] forceSet() -> _set()
    • [x] forceSetAll() removed
    • [x] forceGet() -> _get()
    • [x] repository() -> _repository()
    • [x] enableAutoRefresh() -> _enableAutoRefresh()
    • [x] disableAutoRefresh() -> _disableAutoRefresh()
    • [x] withoutAutoRefresh() -> _withoutAutoRefresh()
    • [x] assertPersisted() removed
    • [x] assertNotPersisted() removed
    • [x] introduce Proxy interface
    • [x] final objects cannot be proxified
  • [x] ~Zenstruck\Foundry\anonymous() -> Zenstruck\Foundry\factory()~ (factory() will be re-added in 2.x)
  • [x] Zenstruck\Foundry\create() -> Zenstruck\Foundry\Persistence\persist()
  • [x] Zenstruck\Foundry\create_many() removed
  • [x] Zenstruck\Foundry\instantiate() -> Zenstruck\Foundry\object()
  • [x] Zenstruck\Foundry\instantiate_many() removed
  • [x] Zenstruck\Foundry\repository() -> Zenstruck\Foundry\Persistence\repository()
  • [x] Zenstruck\Foundry\Test\TestState -> Zenstruck\Foundry\Test\UnitTestConfig (better name?)
  • [x] Zenstruck\Foundry\Factory::delayFlush() -> Zenstruck\Foundry\Persistence\flush_after()
  • [x] Zenstruck\Foundry\Test\Factories
    • [x] disablePersist() -> Zenstruck\Foundry\Persistence\disable_persisting()
    • [x] enablePersist() -> Zenstruck\Foundry\Persistence\enable_persisting()
    • [x] disable_persisting() / enable_persisting() can non more be called in a unit test
  • [x] Zenstruck\Foundry\Instantiator to Zenstruck\Foundry\Object\Instantiator
    • [x] new Instantiator() => Instantiator::withConstructor()
    • [x] alwaysForceProperties() => alwaysForce() + parameters are spread
    • [x] allowExtraAttributes() => allowExtra() + parameters are spread
    • [x] Instantiator::withConstructor() will throw an exception if class's constructor is not public
  • [x] Zenstruck\Foundry\RepositoryProxy to Zenstruck\Foundry\Persistence\RepositoryDecorator
  • [x] Zenstruck\Foundry\RepositoryAssertions to Zenstruck\Foundry\Persistence\RepositoryAssertions
  • [x] withoutPersisting() & co are only on PersistObjectFactory
  • [x] Proxy::forceGet() was mistakenly removed and rector should convert to _get()
  • [x] Factory::faker() => faker()
  • [x] FactoryCollection::set() to deprecate
  • [x] Instantiator::forceGet() to deprecate
  • [x] Instantiator::forceSet() to deprecate
  • [x] bc layer on sequences needs to be rolled-back
  • [x] ~randomRange() does not accept 0 anymore~ we'll still allow 0 in 2.x
  • [x] deprecate FactoryCollection::factory()
  • [x] RepositoryProxy::findOneBy() second argument $orderBy should be deprecated
  • [ ] ModelFactory::new() used to accept string (should we deprecate this?)
  • [x] RepositoryDecorator methods now returns T and not Proxy
  • [ ] Rector
    • [x] Don't replace extended factory if extending a user-defined factory
    • [x] Calls to parent::getDefaults() on factories that extend other user-defined factories
    • [ ] see how we can improve FQCN and FQFN which are not imported
    • [x] functions changed to object() are not proxied
    • [x] functions changed to persist() are not proxied

EDIT: I think the two following are ok-ish: for the first problem. Both problems are fixed byt rector rules.

  • [ ] ~no deprecation is thrown around "old" classes like Proxy, RepositoryProxy, etc... not sure it is really a problem, but we're not covered by deprecations for this~ I don't think a lot of people type-hint RepositoryProxy
  • [ ] ~deprecation was never thrown about Factory::instantiate()'s return type, althought Ive added #[ReturnTypeWillChange]~ For the second one: if the problem exist, tests will fail in a very explicit way

nikophil avatar Nov 07 '23 17:11 nikophil

Bundle config diff:

zenstruck_foundry:
-    auto_refresh_proxies: null
    instantiator:
-        without_constructor:  false
+        use_constructor:  true
        allow_extra_attributes: false
        always_force_properties: false
        service:              null
+    orm:
+        auto_persist:         true
+        reset:
+            connections: [default]
+            entity_managers: [default]
+            mode: schema
+    mongo:
+        auto_persist:         true
+        reset:
+            document_managers: [default]
-    database_resetter:
-        enabled:              true
-        orm:
-            connections:          []
-            object_managers:      []
-            reset_mode:           schema
-        odm:
-            object_managers:      []
    global_state:         []
-    make_factory:
-        default_namespace:    Factory

nikophil avatar Nov 10 '23 15:11 nikophil

Here's some info on my upgrade to this branch and running rector:

Before: Remaining direct deprecation notices (3342)

After (and issues below fixed):

Remaining direct deprecation notices (13) :tada:
  38x: Since zenstruck/foundry 1.37.0: Calling instance method "Zenstruck\Foundry\Object\Instantiator::withoutConstructor()" is deprecated and will be removed in 2.0. Use static call instead: "Zenstruck\Foundry\Object\Instantiator::withoutConstructor()" instead.

  12x: Since zenstruck\foundry 1.37.0: Method "Zenstruck\Foundry\Proxy::object()" is deprecated and will be removed in 2.0. Use "Zenstruck\Foundry\Proxy::_real()" instead.

  11x: Since zenstruck\foundry 1.37.0: Method "Zenstruck\Foundry\Proxy::save()" is deprecated and will be removed in 2.0. Use "Zenstruck\Foundry\Proxy::_save()" instead.

  9x: Since zenstruck\foundry 1.37.0: Method "Zenstruck\Foundry\Proxy::forceSet()" is deprecated and will be removed in 2.0. Use "Zenstruck\Foundry\Proxy::_set()" instead.

  2x: Since zenstruck\foundry 1.37.0: Method "Zenstruck\Foundry\Proxy::forceSetAll()" is deprecated and will be removed in 2.0 without replacement.

  1x: Since zenstruck\foundry 1.37.0: Passing a callable to method "Zenstruck\Foundry\Factory::sequence()" is deprecated and will be removed in 2.0.

  1x: Since zenstruck\foundry 1.37: Usage of "Zenstruck\Foundry\anonymous()" function is deprecated and will be removed in 2.0. Use the "Zenstruck\Foundry\Persistence\proxy_factory()" function instead.
Remaining indirect deprecation notices (199)
  175x: Since zenstruck\foundry 1.37.0: Method "Zenstruck\Foundry\Proxy::object()" is deprecated and will be removed in 2.0. Use "Zenstruck\Foundry\Proxy::_real()" instead.

  1x: The "Zenstruck\Foundry\Factory::create()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\ObjectFactory".

  1x: The "Zenstruck\Foundry\ObjectFactory::new()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\ObjectFactory::create()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\ObjectFactory::createOne()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\ObjectFactory::createSequence()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::findOrCreate()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::first()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::last()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::random()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::randomOrCreate()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::randomSet()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::randomRange()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::all()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::find()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::findBy()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

Issues: Not sure if all these can/should be fixed.

  • [ ] FQCN and FQFN not imported (easily fixed en mass with phpstorm)
  • [x] factories that extend other user-defined factories had their extends base class changed
  • [x] forceGet issue
  • [x] calls to parent::getDefaults() on factories that extend other user-defined factories
  • [x] functions changed to object() are not proxied
  • [x] functions changed to persist() are not proxied

kbond avatar Jan 10 '24 20:01 kbond