Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support live testing for developers #221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ Then run the unit tests as per normal.

N.B. you can study the `.github/workflows/tests.yml` file to see how we run these tests on our build servers by way of example.

### OPTIONAL: Creating a LIVE test locally

1. copy `phpunit.xml.dist` file into `phpunit.xml` file
2. in the `phpunit.xml` file:
* uncomment part, where `LIVE_TEST_ENDPOINT`, `LIVE_TEST_USERNAME` and `LIVE_TEST_PASSWORD` environment variables are defined
* populate them with the corresponding values
3. write the desired LIVE test in the `ApiTest::testLive` method (e.g. `$api->addWorklog('JRA-12', '12m');`)
4. run it using `vendor/bin/phpunit --filter testLive` command
5. confirm, that results in your Jira instance are as expected
6. rollback changes to the `ApiTest::testLive` method before sending a PR

### Running Test Suite

Make sure that you don't break anything with your changes by running:
Expand Down
19 changes: 11 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>

<!--
<php>
<!--
<php>
<server name="REPO_URL" value="http://localhost/"/>
</php>
<server name="LIVE_TEST_ENDPOINT" value="https://site.atlassian.net/"/>
<server name="LIVE_TEST_USERNAME" value=""/>
<server name="LIVE_TEST_PASSWORD" value=""/>
</php>
-->
</phpunit>
3 changes: 3 additions & 0 deletions phpunit10.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<!--
<php>
<server name="REPO_URL" value="http://localhost/"/>
<server name="LIVE_TEST_ENDPOINT" value="https://site.atlassian.net/"/>
<server name="LIVE_TEST_USERNAME" value=""/>
<server name="LIVE_TEST_PASSWORD" value=""/>
</php>
-->
</phpunit>
3 changes: 3 additions & 0 deletions phpunit7.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<!--
<php>
<server name="REPO_URL" value="http://localhost/"/>
<server name="LIVE_TEST_ENDPOINT" value="https://site.atlassian.net/"/>
<server name="LIVE_TEST_USERNAME" value=""/>
<server name="LIVE_TEST_PASSWORD" value=""/>
</php>
-->
</phpunit>
3 changes: 3 additions & 0 deletions phpunit9.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<!--
<php>
<server name="REPO_URL" value="http://localhost/"/>
<server name="LIVE_TEST_ENDPOINT" value="https://site.atlassian.net/"/>
<server name="LIVE_TEST_USERNAME" value=""/>
<server name="LIVE_TEST_PASSWORD" value=""/>
</php>
-->
</phpunit>
18 changes: 17 additions & 1 deletion tests/Jira/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use chobie\Jira\Api;
use chobie\Jira\Api\Authentication\AuthenticationInterface;
use chobie\Jira\Api\Authentication\Basic;
use chobie\Jira\Api\Result;
use chobie\Jira\IssueType;
use Prophecy\Prophecy\ObjectProphecy;
Expand Down Expand Up @@ -495,6 +496,21 @@ public function testDeleteWorkLogWithCustomParams()
$this->assertEquals(json_decode($response, true), $actual, 'The response is json-decoded.');
}

public function testLive()
{
if ( empty($_SERVER['LIVE_TEST_ENDPOINT']) ) {
$this->markTestSkipped('The "LIVE_TEST_ENDPOINT" environment variable not set.');
}

$api = new Api(
$_SERVER['LIVE_TEST_ENDPOINT'],
new Basic($_SERVER['LIVE_TEST_USERNAME'], $_SERVER['LIVE_TEST_PASSWORD'])
);

// Write you test here, but don't commit.
$this->assertTrue(true);
}

/**
* Expects a particular client call.
*
Expand All @@ -510,7 +526,7 @@ public function testDeleteWorkLogWithCustomParams()
protected function expectClientCall(
$method,
$url,
$data = array(),
$data,
$return_value,
$is_file = false,
$debug = false
Expand Down
Loading