Uploaded image for project: 'Couchbase PHP client library'
  1. Couchbase PHP client library
  2. PCBC-513

Consider removing final from PHP classes

    XMLWordPrintable

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.4.1
    • 2.4.2
    • None
    • None

    Description

      A lot of classes, including Cluster, Bucket and BucketManager, are marked as final. Since this disables user from extending the classes, it also disables testing frameworks like PHPUnit and Mockery from mocking them.

      This makes it really hard to unit test classes which use any of these final classes. (I can of course work around this by using proxy classes, but it adds a lot of ugly stuff to my codebase.)

      Why were these classes marked as final in the first place? And could it be reverted for the purpose of unit testing/mocking?

      Attachments

        For Gerrit Dashboard: PCBC-513
        # Subject Branch Project Status CR V

        Activity

          I've made them final to protect from extending and possible future API issues.

          avsej Sergey Avseyev added a comment - I've made them final to protect from extending and possible future API issues.
          demontpx Bert Hekman added a comment - - edited

          I'm aware what final does, but I still don't understand why you would mark the classes with it. Isn't it the clients responsibility to make sure the subclass they create are correct? I'm also not sure what you mean by future API issues.

          If you really don't want to remove the final's from the classes, it would also be a possibility to add interfaces to the classes to program against, which would make it a lot easier to mock and unit test.

          demontpx Bert Hekman added a comment - - edited I'm aware what final does, but I still don't understand why you would mark the classes with it. Isn't it the clients responsibility to make sure the subclass they create are correct? I'm also not sure what you mean by future API issues. If you really don't want to remove the final's from the classes, it would also be a possibility to add interfaces to the classes to program against, which would make it a lot easier to mock and unit test.

          People

            avsej Sergey Avseyev
            demontpx Bert Hekman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty