Skip to content

Commit

Permalink
fix example module
Browse files Browse the repository at this point in the history
  • Loading branch information
sayan goswami committed Aug 3, 2023
1 parent 7f7fc15 commit ea3bc73
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .phpunit.cache/test-results

Large diffs are not rendered by default.

38 changes: 20 additions & 18 deletions example/src/ExampleComplexity.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
/**
* An example class to provide some cyclomatic complexity for PHPLOC to report.
*/
class ExampleComplexity {
class ExampleComplexity
{

/**
* Creates some cyclomatic complexity.
*
* @return int
* An arbitrary number.
*/
public function createComplexity(): int {
$x = 0;
for ($y = 0; $y < 10; $y++) {
try {
$x += random_int(0, 10);
}
catch (Exception $e) {
$x++;
}
/**
* Creates some cyclomatic complexity.
*
* @return int
* An arbitrary number.
*/
public function createComplexity(): int
{
$x = 0;
for ($y = 0; $y < 10; $y++) {
try {
$x += random_int(0, 10);
}
catch (Exception $e) {
$x++;
}
}
return $x;
}
return $x;
}

}
28 changes: 14 additions & 14 deletions example/tests/Drupal/Nightwatch/Tests/exampleTest.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// noinspection JSUnusedGlobalSymbols
module.exports = {
'@tags': ['example'],
before(browser) {
browser.drupalInstall();
},
after(browser) {
browser.drupalUninstall();
},
'Test page': browser => {
browser
.drupalRelativeURL('/')
.waitForElementVisible('body', 1000)
.assert.containsText('body', 'Log in')
.drupalLogAndEnd({ onlyOnError: "FALSE" });
},
'@tags': ['example'],
before(browser) {
browser.drupalInstall();
},
after(browser) {
browser.drupalUninstall();
},
'Test page': browser => {
browser
.drupalRelativeURL('/')
.waitForElementVisible('body', 1000)
.assert.containsText('body', 'Log in')
.drupalLogAndEnd({ onlyOnError: "FALSE" });
},
};
20 changes: 11 additions & 9 deletions example/tests/src/Functional/ExampleLoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@

use Drupal\Tests\BrowserTestBase;

class ExampleLoginTest extends BrowserTestBase {
class ExampleLoginTest extends BrowserTestBase
{

protected $defaultTheme = 'claro';
protected $defaultTheme = 'claro';

private $privilegedUser;
private $privilegedUser;

public function testExampleLogin(): void {
$this->privilegedUser = $this->drupalCreateUser();
$this->drupalLogin($this->privilegedUser);
public function testExampleLogin(): void
{
$this->privilegedUser = $this->drupalCreateUser();
$this->drupalLogin($this->privilegedUser);

$this->drupalGet('user');
$this->assertSession()->statusCodeEquals(200);
$this->drupalGet('user');
$this->assertSession()->statusCodeEquals(200);

}
}

}
16 changes: 9 additions & 7 deletions example/tests/src/FunctionalJavascript/ExampleHomeLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

use Drupal\FunctionalJavascriptTests\WebDriverTestBase;

class ExampleHomeLinkTest extends WebDriverTestBase {
class ExampleHomeLinkTest extends WebDriverTestBase
{

protected $defaultTheme = 'claro';
protected $defaultTheme = 'claro';

public function testHomePageLink(): void {
$page = $this->getSession()->getPage();
$content = $page->findLink('Log in');
$this->assertTrue($content->isVisible());
}
public function testHomePageLink(): void
{
$page = $this->getSession()->getPage();
$content = $page->findLink('Log in');
$this->assertTrue($content->isVisible());
}

}
83 changes: 44 additions & 39 deletions example/tests/src/Unit/ExampleUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,49 @@
/**
* Provides an example PHPUnit test for ORCA.
*/
class ExampleUnitTest extends TestCase {

/**
* Demonstrates designating a test to run only during own builds.
*/
public function testPrivatePseudoGroup(): void {
self::assertTrue(TRUE, 'Performed private test.');
}

/**
* Demonstrates designating a test to run during OTHER packages' builds.
*
* @group orca_public
*/
public function testPublicGroup(): void {
self::assertTrue(TRUE, 'Performed public test.');
}

/**
* Demonstrates designating a test to never run by ORCA.
*
* @group orca_ignore
*/
public function testIgnoreGroup(): void {
self::fail('Ran ignored test.');
}

/**
* Demonstrates ignoring deprecated code in test files.
*
* This function is private so that it will not be run by PHPUnit
* because this is only for static analysis.
*
* phpcs:disable DrupalPractice.Objects.UnusedPrivateMethod.UnusedMethod
*/
private function testDeprecateCodeInTestFiles(): void {
// This is a deprecated function which should not be caught by drupal-check.
file_create_url("https://example.com");
}
class ExampleUnitTest extends TestCase
{

/**
* Demonstrates designating a test to run only during own builds.
*/
public function testPrivatePseudoGroup(): void
{
self::assertTrue(true, 'Performed private test.');
}

/**
* Demonstrates designating a test to run during OTHER packages' builds.
*
* @group orca_public
*/
public function testPublicGroup(): void
{
self::assertTrue(true, 'Performed public test.');
}

/**
* Demonstrates designating a test to never run by ORCA.
*
* @group orca_ignore
*/
public function testIgnoreGroup(): void
{
self::fail('Ran ignored test.');
}

/**
* Demonstrates ignoring deprecated code in test files.
*
* This function is private so that it will not be run by PHPUnit
* because this is only for static analysis.
*
* phpcs:disable DrupalPractice.Objects.UnusedPrivateMethod.UnusedMethod
*/
private function testDeprecateCodeInTestFiles(): void
{
// This is a deprecated function which should not be caught by drupal-check.
file_create_url("https://example.com");
}

}
16 changes: 9 additions & 7 deletions example/vendor/ExampleFailingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
* run by ORCA. This failing test is used to verify that ORCA excludes the
* vendor directory as expected.
*/
class ExampleFailingTest extends TestCase {
class ExampleFailingTest extends TestCase
{

/**
* ORCA should never run this test.
*/
public function testExcludeVendorDirectory(): void {
self::assertTrue(FALSE);
}
/**
* ORCA should never run this test.
*/
public function testExcludeVendorDirectory(): void
{
self::assertTrue(false);
}

}

0 comments on commit ea3bc73

Please sign in to comment.