Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhedstrom’s picture

Status: Active » Needs review
FileSize
4.54 KB

Of the 4 classes listed in summary, only 2 are easy conversions, here in this patch.

The other 2 require either a database connection, or writing out of files and expect a bootstrapped system.

ParisLiakos’s picture

Status: Needs review » Needs work

cool!

+++ b/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.phpundefined
@@ -1,21 +1,21 @@
+ * Definition of Drupal\Tests\Core\Controller\ExceptionControllerTest.

Should be Contains \Drupal\Tests\Core\Controller\ExceptionControllerTest

+++ b/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.phpundefined
@@ -1,21 +1,21 @@
@@ -33,7 +33,7 @@ public function test405HTML() {

lets rename it to test405Html() since we are here:)

+++ b/core/tests/Drupal/Tests/Core/Password/PasswordHashingTest.phpundefined
@@ -2,18 +2,18 @@
+ * Definition of Drupal\Tests\Core\Password\PasswordHashingTest.

same as above with Contains \...

+++ b/core/tests/Drupal/Tests/Core/Password/PasswordHashingTest.phpundefined
@@ -2,18 +2,18 @@
@@ -37,7 +37,7 @@ function testPasswordHashing() {

lets add public visibility to this method

jhedstrom’s picture

Status: Needs work » Needs review
FileSize
5.21 KB
2.43 KB

This should cover #2.

Status: Needs review » Needs work

The last submitted patch, system-system-phpunit-2008566-03.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Needs review
Berdir’s picture

Berdir’s picture

Status: Needs review » Needs work

PasswordHashingTest was converted to a DUBT test because the Password class now type hints on UserInterface and uses methods.

It's still possible to convert it, but now you need to mock the user objects.

Berdir’s picture

Status: Needs work » Needs review
FileSize
7.02 KB

Hm, that wasn't trivial.

jhedstrom’s picture

ParisLiakos’s picture

  1. +++ b/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php
    @@ -1,21 +1,24 @@
    +class ExceptionControllerTest extends UnitTestCase {
    

    seems this test got already converted to PHPunit in another issue

  2. +++ b/core/tests/Drupal/Tests/Core/Password/PasswordHashingTest.php
    @@ -2,25 +2,20 @@
    +class PasswordHashingTest extends UnitTestCase {
    

    here we need a
    @group Drupal
    in the class docblock

ParisLiakos’s picture

Status: Needs review » Needs work
kim.pepper’s picture

Status: Needs work » Needs review
FileSize
4.53 KB

Re-roll.

Status: Needs review » Needs work

The last submitted patch, 12: 2008566-system-phpunit-12.patch, failed testing.

The last submitted patch, 12: 2008566-system-phpunit-12.patch, failed testing.

kim.pepper’s picture

Status: Needs work » Needs review
FileSize
7.96 KB
6.48 KB

I've tried to clean up this unit test class a bit. Changes include:

  • Split out a specific test for testing hash boundaries, instead of assuming it is working
  • Mock UserInterface instead of a concrete class
  • Move set up code to setUp() and use properties for re-used variables.

The last submitted patch, 15: 2008566-system-phpunit-15.patch, failed testing.

The last submitted patch, 15: 2008566-system-phpunit-15.patch, failed testing.

kim.pepper’s picture

PHP Fatal error: Class Mock_UserInterface_82494099 must implement interface Traversable as part of either Iterator or IteratorAggregate in Unknown on line 0

kim.pepper’s picture

This splits out the rehashing to another test, and fixes the issue with using UserInterface.

larowlan’s picture

+++ b/core/tests/Drupal/Tests/Core/Password/PasswordHashingTest.php
@@ -0,0 +1,152 @@
+    // noop

nitpick, needs to start with a capital letter and end with a .

Was expecting to see conversion of
System/SettingsRewriteTest.php
System/ExceptionControllerTest.php
System/SystemInitTest.php

as well, as per issue summary

kim.pepper’s picture

Issue summary: View changes
FileSize
540 bytes
8.2 KB

Thanks for the review.

PasswordHashingTest is the only one that can be converted.

ExceptionControllerTest got converted already. See comment #10

System/SettingsRewriteTest.php and System/SystemInitTest.php either require a fully bootstrapped system, or access to the database.

K

kim.pepper’s picture

Issue summary: View changes
kim.pepper’s picture

Title: Convert system module's System unit tests to phpunit » Convert PasswordHashingTest unit tests to phpunit
dawehner’s picture

  1. +++ b/core/tests/Drupal/Tests/Core/Password/PasswordHashingTest.php
    @@ -0,0 +1,152 @@
    +  public static function getInfo() {
    

    Drupal core now even uses @inheritdoc for getInfo

  2. +++ b/core/tests/Drupal/Tests/Core/Password/PasswordHashingTest.php
    @@ -0,0 +1,152 @@
    +    $this->assertTrue($this->hashedPassword != $this->md5Password, 'Password hash changed.');
    ...
    +    $this->assertTrue($rehashed_password != $this->hashedPassword, 'Password hash changed again.');
    

    This could use assertNotEquals

  3. +++ b/core/tests/Drupal/Tests/Core/Password/PasswordHashingTest.php
    @@ -0,0 +1,152 @@
    + * Definition of Drupal\system\Tests\System\PasswordHashingTest.
    

    Should be contains.

kim.pepper’s picture

Thanks dawehner!

Fixes issues in #24

kim.pepper’s picture

Missed one!

kim.pepper’s picture

Fixed "Contains of ... "

The last submitted patch, 26: 2008566-system-phpunit-26.patch, failed testing.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

steeloctopus’s picture

I have applied the patch and all the PHPUnit test still work.

steeloctopus’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/tests/Drupal/Tests/Core/Password/PasswordHashingTest.php
    @@ -0,0 +1,155 @@
    +  /**
    +   * Modules to enable.
    +   *
    +   * @var array
    +   */
    +  public static $modules = array('field', 'user');
    

    We're in a PHPUnit test - this is not needed :)

  2. +++ b/core/tests/Drupal/Tests/Core/Password/PasswordHashingTest.php
    @@ -0,0 +1,155 @@
    +  /**
    +   * @var \Drupal\user\UserInterface
    +   *   The user for testing.
    +   */
    +  protected $user;
    +
    +  /**
    +   * @var string
    +   *   The raw password.
    +   */
    +  protected $password;
    +
    +  /**
    +   * @var string
    +   *   The md5 password.
    +   */
    +  protected $md5Password;
    +
    +  /**
    +   * @var string
    +   *   The hashed password.
    +   */
    +  protected $hashedPassword;
    +
    +  /**
    +   * @var \Drupal\Core\Password\PhpassHashedPassword
    +   *   The password hasher under test.
    +   */
    +  protected $passwordHasher;
    

    The doc blocks should be like this:

    +  /**
    +   * The md5 password.
    +   *
    +   * @var string
    +   */
    +  protected $md5Password;
    
  3. +++ b/core/tests/Drupal/Tests/Core/Password/PasswordHashingTest.php
    @@ -0,0 +1,155 @@
    +  /**
    +   * @var \Drupal\user\UserInterface
    +   *   The user for testing.
    +   */
    +  protected $user;
    

    The @var for the user object should be @var \PHPUnit_Framework_MockObject_MockObject|\Drupal\user\UserInterface

kim.pepper’s picture

Status: Needs work » Needs review
FileSize
8.2 KB
1.62 KB

Fixes for #32

Berdir’s picture

Status: Needs review » Needs work

The last submitted patch, 33: 2008566-system-phpunit-33.patch, failed testing.

kim.pepper’s picture

Issue tags: +needs re-roll
kim.pepper’s picture

Status: Needs work » Needs review
Issue tags: -needs re-roll
FileSize
8.05 KB

Re-rolled #33 plus modernised test meta info.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Awesome! I think it is fine to mark some methods as public.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 6c5130d and pushed to 8.x. Thanks!

  • alexpott committed 6c5130d on 8.x
    Issue #2008566 by kim.pepper, jhedstrom, Berdir: Convert...

Status: Fixed » Closed (fixed)

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