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

Add tests and correct TouchTask behavior #1456

Merged
merged 16 commits into from
Dec 7, 2020

Conversation

BlairCooper
Copy link
Contributor

Fixes #1452, #1453, #1454

Fixes #1452, #1453, #1454

- Check return value of strtotime() - #1452
- Change millis member of TouchTask to seconds to reflect what it
actually contains. Retain millis attribute for continuity with the ANT
Touch task - #1453
- Add tests for validating timestamps and error conditions - #1454
@codecov
Copy link

codecov bot commented Nov 28, 2020

Codecov Report

Merging #1456 (3e92f35) into master (9959487) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1456      +/-   ##
============================================
+ Coverage     52.68%   52.72%   +0.03%     
- Complexity     9205     9207       +2     
============================================
  Files           469      469              
  Lines         22351    22357       +6     
============================================
+ Hits          11776    11787      +11     
+ Misses        10575    10570       -5     
Impacted Files Coverage Δ Complexity Δ
classes/phing/tasks/system/TouchTask.php 93.54% <100.00%> (+6.19%) 43.00 <2.00> (+2.00)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9959487...3e92f35. Read the comment docs.

* drift to account for a lag between when we noted the time and when
* the file was touched.
*/
$this->assertThat(filemtime($testFile), new IsEqual($nowTime, 1), 'File timestamp not within 1 second of now');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->assertEqualsWithDelta(filemtime($testFile), $nowTime, 1, 'File timestamp not within 1 second of now')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

<filelist dir="." files="${tmp.dir}/idonotexist" />
<mapper type="merge" to="${tmp.dir}/touchtest" />
</touch>
</target>

<target name="testMillis">
<touch file="${tmp.dir}/millis-file" millis="946684799864" /> <!-- Friday, December 31, 1999 11:59:59.864 PM -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please test against milliseconds not microseconds.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is milliseconds:
image

@@ -1,4 +1,6 @@
<?php
use PHPUnit\Framework\Constraint\IsEqual;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move after file comment!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

$testFile = $this->getProject()->getProperty('tmp.dir') . '/millis-file';
$this->assertFileExists($testFile);

$this->assertEquals('December 31 1999 23:59:59', date("F d Y H:i:s", filemtime($testFile)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean something like this?

$this->assertEquals('December 31 1999 23:59:59.000000', date("F d Y H:i:s.u", filemtime($testFile)));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems unnecessary as filemtime() would always return the milliseconds as .000000.

siad007 and others added 9 commits November 30, 2020 22:20
Fixes #1452, #1453, #1454

- Check return value of strtotime() - #1452
- Change millis member of TouchTask to seconds to reflect what it
actually contains. Retain millis attribute for continuity with the ANT
Touch task - #1453
- Add tests for validating timestamps and error conditions - #1454
Change testDefaultToNow() to use assertEqualsWithDelta instead of
assertThat with an IsEquals constraint.
Copy link
Member

@siad007 siad007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BlairCooper please check https://github.com/phingofficial/phing/pull/1456/checks?check_run_id=1513668571#step:5:633

[phpunit] Testsuite: TimerTest
  [phpunit] Tests run: 1, Risky: 0, Warnings: 0, Failures: 1, Errors: 0, Incomplete: 0, Skipped: 0, Time elapsed: 0.01496 s
  [phpunit] testTimer FAILED
  [phpunit] Failed asserting that '0.00194' matches expected 0.0.

Hmm seems not related. So I will approve. THX for your PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

[TouchTask] allows invalid datetime values to be specified
2 participants