Skip to content

Instantly share code, notes, and snippets.

@kevinquillen
Last active January 30, 2018 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinquillen/85baa1fa69f49d1c34aa81369405d47e to your computer and use it in GitHub Desktop.
Save kevinquillen/85baa1fa69f49d1c34aa81369405d47e to your computer and use it in GitHub Desktop.
Example PHPUnit test with UnitTestCase testing a method of a utility class https://gist.github.com/kevinquillen/d7efe7e2bce417289f8fabc2e2f1fe62
<?php
namespace Drupal\Tests\iana_netforum_auth\Unit;
use Drupal\Tests\UnitTestCase;
use Drupal\iana_netforum_auth\Utility\EmailMatcher;
/**
* Test email matching component class.
*
* @group iana_netforum_auth
*
* @coversDefaultClass \Drupal\iana_netforum_auth\Utility\EmailMatcher
*/
class EmailMatcherTest extends UnitTestCase {
/**
* Test that the EmailMatcher method returns what we expect.
*
* @dataProvider providerTestMatch
* @covers ::emailDomainMatch
*/
public function testMatch($email_address, $domain, $expected) {
$this->assertEquals($expected, EmailMatcher::emailDomainMatch($email_address, $domain));
}
/**
* Data provider for testMatch().
*
* @see testMatch()
*
* @return array
* An array containing:
* - The email address provided.
* - The domain we want to check.
* - The bool that should be returned.
*/
public function providerTestMatch() {
return [
['tester@velir.com', 'velir.com', TRUE],
['tester@velr.com', 'velir.com', FALSE],
['tester@gmail.com', 'velir.com', FALSE],
['velir.com', 'velir.com', FALSE],
['velir@velir.org', 'velir.com', FALSE],
['tester@velir.com@gmail.com', 'velir.com', FALSE],
['tester@velir.com@velir.com', 'velir.com', FALSE]
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment