Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add a BC layer for 2.x #515

Merged
merged 4 commits into from
Mar 25, 2024
Merged

refactor: add a BC layer for 2.x #515

merged 4 commits into from
Mar 25, 2024

Conversation

nikophil
Copy link
Member

@nikophil nikophil commented Nov 7, 2023

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

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

src/Proxy.php Show resolved Hide resolved
@kbond
Copy link
Member

kbond commented Jan 10, 2024

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) 🎉
  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)
  • factories that extend other user-defined factories had their extends base class changed
  • forceGet issue
  • calls to parent::getDefaults() on factories that extend other user-defined factories
  • functions changed to object() are not proxied
  • functions changed to persist() are not proxied

@nikophil nikophil force-pushed the 1.x-bc branch 2 times, most recently from 4c98640 to aa01e77 Compare February 13, 2024 07:57
@nikophil nikophil marked this pull request as ready for review March 1, 2024 10:15
@nikophil nikophil force-pushed the 1.x-bc branch 5 times, most recently from 967932b to 8e1c317 Compare March 1, 2024 15:55
@nikophil nikophil force-pushed the 1.x-bc branch 12 times, most recently from 97c785e to 3f71782 Compare March 21, 2024 07:24
refactor: Foundry 2 BC layer

refactor: deprecate ModelFactory

refactor: deprecate ModelFactory::getDefaults()

refactor: deprecate ModelFactory::getClass()

refactor: add #[\ReturnTypeWillChange] to PersistentProxyObjectFactory::initialize()

refactor: deprecate proxy class

refactor: deprecate stuff in functions.php

refactor: deprecate RepositoryProxy

refactor: deprecate stuff in Instantiator

bot: fix cs [skip ci]

minor: deprecate more stuff

* refactor: deprecate passing callable to sequence

* refactor: deprecate usage of disable/enable_persisting without doctrine

* refactor: deprecate TestState for UnitTestConfig

bot: fix cs [skip ci]

refactor: introduce PersistentObjectFactory and deprecate PersistentProxyObjectFactory with final (#518)

* refactor: introduce PersistentObjectFactory and deprecate PersistentProxyObjectFactory with final

* refactor: introduce persistent_factory()

bot: fix cs [skip ci]

refactor: deprecate config database_resetter (#523)

* refactor: deprecate config database_resetter.orm in favor of orm.reset

* refactor: deprecate config database_resetter.odm in favor of mongo.reset

bot: fix cs [skip ci]

refactor: deprecate config instantiator.without_constructor (#522)

bot: fix cs [skip ci]

refactor: add BC layer for methods in Instantiator (#535)

refactor: change phpstan FactoryCollection return type (#530)

bot: fix cs [skip ci]

refactor: remove not working BC layer on Factory::__construct() (#529)

refactor(bc layer): introduce Proxy interface (#528)

bot: fix cs [skip ci]

refactor: deprecate config auto_refresh_proxies (#524)

bot: fix cs [skip ci]

refactor: better deprecations (#541)

bot: sync with template [skip ci]

bot: fix cs [skip ci]

feat: introduce ObjectFactory (#543)

bot: fix cs [skip ci]

feat: introduce rector rules 🎉 (#544)

refactor: create ObjectFactory with make:factory --no-persistence (#546)

refactor: more deprecations (#547)

* refactor: deprecate Factory::faker() outisde of a factory

* refactor: deprecate FactoryCollection::set()

bot: fix cs [skip ci]

fix: remove directory utils/rector/vendor from git

fix: rename Proxy::get() into Proxy::forceGet()

fix: rollback BC layer on sequence() attributes

fix(rector): handle extending user-defined factory class

fix(rector): proxify create() and instantiate() transformation (#549)

fix(rector): don't remove ->object() call for create() or instantiate()

refctor: deprecate FactoryCollection::factory() (#550)

refactor: deprecate using proxy with anonymous class

bot: fix cs [skip ci]

docs(bc layer): document known BC breaks (#554)

refactor: deprecate $orderBy argument in RepositoryDecorator::findOneBy() (#551)

fix(rector): bump rector/rector 1.0

fix(bc layer): install php cs fixer for maker bundle (#560)

refactor(bc layer): deprecate passing states as string to Factory::new() (#559)

bot: fix cs [skip ci]

minor: fix some types for sca

rector: remove un-needed Factory<Proxy<>> php docs

rector: migrate old proxy phpdoc to generic ones

rector: use getName() instead of cast to string nodes

rector: fix @method parameters rendering

bc: deprecate config auto_refresh_proxies

bc: introduce ProxyRepositoryDecorator

bot: fix cs [skip ci]

fix(proxy): assert object is not scheduled for insert before throwing in _refresh

minor(rector): change doc to comply to rector 1.0

bc: throw deprecation when calling Configuration::disableDefaultProxyAutoRefresh()

bot: fix cs [skip ci]

bc: throw deprecation when calling Configuration::disableDefaultProxyAutoRefresh()

bc: add repo class in ProxyRepositoryDecorator @methods in rector + maker

bot: fix cs [skip ci]

bc: fix Proxy sca problem in ModelFactory

bot: fix cs [skip ci]

bc: fix Proxy sca problem in ModelFactory

bot: fix cs [skip ci]

bc: fix PersistentObjectFactory @methods

fix(bc): add missing import

bc(rector): remove useless "unproxify" array_map

bc(rector): fix factories @method phpdoc

bc(rector): clean rector

bot: fix cs [skip ci]
@nikophil nikophil merged commit bbcef6a into 1.x Mar 25, 2024
40 checks passed
@nikophil nikophil deleted the 1.x-bc branch March 29, 2024 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants