Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lauriii created an issue. See original summary.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joelpittet’s picture

Status: Active » Postponed (maintainer needs more info)

Is this still needed? Constructor injection requires more to mock when PHPUnit testing.

This would currently be 4 new constructor parameters and more if we add more services providing twig filters and functions.

lauriii’s picture

Status: Postponed (maintainer needs more info) » Active

This is definitely still needed. It is bad practice to use setter methods for required dependencies. Caller code doesn't expect that it has to call setter methods to provide needed dependencies and therefore will cause easily unexpected errors if they're not supplied.

lauriii’s picture

Status: Active » Needs review
FileSize
0 bytes

Status: Needs review » Needs work

The last submitted patch, 6: remove_twigextension-2571633-6.patch, failed testing.

lauriii’s picture

Status: Needs work » Needs review
FileSize
15.37 KB

Something went wrong with the previous patch.. Luckily PHPStorm local history saved me..

Status: Needs review » Needs work

The last submitted patch, 8: remove_twigextension-2571633-8.patch, failed testing.

lauriii’s picture

Version: 8.2.x-dev » 8.3.x-dev
Status: Needs work » Needs review
FileSize
15.37 KB

Re-uploading for 8.3.x

Status: Needs review » Needs work

The last submitted patch, 10: remove_twigextension-2571633-8.patch, failed testing.

lauriii’s picture

Status: Needs work » Needs review
FileSize
16.14 KB
725 bytes

Status: Needs review » Needs work

The last submitted patch, 12: remove_twigextension-2571633-12.patch, failed testing.

lauriii’s picture

Status: Needs work » Needs review
FileSize
16.92 KB
597 bytes
martin107’s picture

Status: Needs review » Reviewed & tested by the community

The change is a nice cleanup/standardization.

Unless there is a specific reason it is better to be more tightly constrained - inject at the point of construction and be done with it .. rather than allow the dependencies to be set dynamically.

I have visually scanned the patch ... all changes make sense.

joelpittet’s picture

Issue summary: View changes

I'm +1 for this now talking to @laurii and @xano because it makes sense that all of our deps are not optional.

+++ b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
@@ -27,25 +22,73 @@
+   * The service under testing.

this is 'system' under testing not 'service' as an acronym but maybe this could be a spelled out variable? The typo can be changed on commit if it's ok to keep that variable name.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Template/TwigExtension.php
@@ -58,63 +58,18 @@ class TwigExtension extends \Twig_Extension {
-  public function setGenerators(UrlGeneratorInterface $url_generator) {
...
-  public function setUrlGenerator(UrlGeneratorInterface $url_generator) {
...
-  public function setThemeManager(ThemeManagerInterface $theme_manager) {
...
-  public function setDateFormatter(DateFormatterInterface $date_formatter) {

I don't think we can remove these in Drupal 8. The rest of the patch looks fine for D8 - we've agreed that constructors can change in minor versions.

lauriii’s picture

Status: Needs work » Needs review
FileSize
17.17 KB
1.78 KB

Yes sir!

lauriii’s picture

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the changes @lauriii and review @alexpott

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
@@ -27,25 +22,73 @@
+  /**
+   * The service under testing.
+   *
+   * @var \Drupal\Core\Template\TwigExtension
+   */
+  protected $sut;
...
+    $this->sut = new TwigExtension($this->renderer, $this->urlGenerator, $this->themeManager, $this->dateFormatter);

Does sut mean system under test or a service under test? I think we should just be descriptive here. Also the problem here is that system under test and unit testing concepts are tricky to define to together. Looking at http://xunitpatterns.com/SUT.html. The test needs to clearly define what it means by system. But just introducing an acronym makes it more difficult to understand for people. For no reason we are making people have to think "What does sut mean and what does it stand for" when the more valuable considerations are does the test test what it claims to.

tuutti’s picture

Status: Needs work » Needs review
FileSize
5.66 KB
17.32 KB
joelpittet’s picture

Status: Needs review » Needs work

The problem isn't the concept of 'system under test' it's just the variable being short. Thanks for trying to resolve @tuutti! I did overhear @lauriii and @alexpott discussing this at the table yesterday at Badcamp, and it just needs a long form name from what I gathered.

Maybe $systemUnderTest?

tuutti’s picture

tuutti’s picture

Status: Needs work » Needs review
tuutti’s picture

...changed code comment to match the variable name.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Thank you for addressing that @tuutti.

alexpott’s picture

Committed dd79f79 and pushed to 8.3.x. Thanks!

diff --git a/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
index eb9e650..396b2f9 100644
--- a/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
+++ b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
@@ -4,8 +4,6 @@
 
 use Drupal\Core\GeneratedLink;
 use Drupal\Core\Render\RenderableInterface;
-use Drupal\Core\Render\RendererInterface;
-use Drupal\Core\Routing\UrlGeneratorInterface;
 use Drupal\Core\StringTranslation\TranslatableMarkup;
 use Drupal\Core\Template\Loader\StringLoader;
 use Drupal\Core\Template\TwigEnvironment;

Unused uses fixed on commit.

diff --git a/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
index 3644237..eb9e650 100644
--- a/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
+++ b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
@@ -50,7 +50,7 @@ class TwigExtensionTest extends UnitTestCase {
   protected $dateFormatter;
 
   /**
-   * The system under testing.
+   * The system under test.
    *
    * @var \Drupal\Core\Template\TwigExtension
    */

Minor improvement on commit.

  • alexpott committed dd79f79 on 8.3.x
    Issue #2571633 by lauriii, tuutti, joelpittet: Remove TwigExtension...
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.