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

unit test added. Part2 #2

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

unit test added. Part2 #2

wants to merge 16 commits into from

Conversation

ivancoff
Copy link

Run this script for testing FileLock module.
Algorithm is follow:

  1. script created file in current folder
  2. trying to lock file
  3. checking that file is locked
  4. trying to read
  5. checking that file is locked
  6. trying to write
  7. checking that file is locked
  8. try to unlock file
  9. checking that file is not locked
  10. trying to read
  11. checking that file is not locked
  12. trying to write
  13. checking that file is not locked
    echo 'done' and exit

Run this script for testing FileLock module.
Algorithm is follow:
1) script created file in current folder
2) trying to lock file
3) checking that file is locked
4) trying to read
5) checking that file is locked
6) trying to write
7) checking that file is locked
8) try to unlock file
9) checking that file is not locked
10) trying to read
11) checking that file is not locked
12) trying to write
13) checking that file is not locked
echo 'done' and exit
@dorantor
Copy link
Owner

Unittests are awesome, but could you please send them in a more "traditional" way? With PHPUnit(preferably) or with Codeception(or any other widely used for unittesting library)?

@dorantor
Copy link
Owner

I've added required travis and coverall integrations, so it would be easier make it properly and see results.

@ivancoff ivancoff changed the title unit test added unit test added. Part2 Oct 31, 2018
@ivancoff
Copy link
Author

sent updated tests for PHPUnit

@dorantor
Copy link
Owner

TravisCI shows that there are some issues. Could you please fix them?

@ivancoff
Copy link
Author

ok, got it

@dorantor
Copy link
Owner

dorantor commented Nov 1, 2018

I don't get it. Why did you rewrote files:

  • composer.json
  • phpunit.xml
  • .travis.yml

by same files? Why not just pull from master? It's same-same 20dd541
Can you please merge master to your code?

Did you run composer check-style? Now, when I look into your code, there are some obvious style issues. For now it's not PSR compliant :(

Copy link
Owner

@dorantor dorantor left a comment

Choose a reason for hiding this comment

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

Currently test doesn't cover locking functionality. Only most basic - create lock, acquire lock, release lock. It's way better then nothing, but maybe you could also add test for locking mechanics also?

$fname = 'tests/lock-test.txt';

//create file
$handle = fopen($fname, 'w') or die('ERROR[0]: Unable to open/create file "'.$fname.'"!');
Copy link
Owner

Choose a reason for hiding this comment

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

Not sure why you need this part, but it should be in setUp(), according to phpunit docs
And should not output anything for sure.

As I can see, you've added this file to repo already, so there is no need to create this file each time.

Copy link
Author

Choose a reason for hiding this comment

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

ok, got it


use PHPUnit\Framework\TestCase;

$fname = 'tests/lock-test.txt';
Copy link
Owner

Choose a reason for hiding this comment

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

Should be a part of test class or variable in test method.

Copy link
Author

Choose a reason for hiding this comment

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

understood


public function testCanBeLocked() {

global $fname;
Copy link
Owner

Choose a reason for hiding this comment

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

You should have a VERY big and good reason to use global keyword. And I don't see any reason to use it here.

Copy link
Author

Choose a reason for hiding this comment

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

agreed

$lock = new \Dorantor\FileLock($fname);

//try to lock file
$this->assertEquals(true, $lock->acquire(),'ERROR[1]: Result of function acquire() not correct!'. PHP_EOL);
Copy link
Owner

Choose a reason for hiding this comment

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

assertEquals() is a static method, so it should be called via self:
self::assertEquals()

Also, there is no need in message in assert - currently it doesn't add any value to test.
Also, it makes sense to replace assertEquals() with assertTrue(). Thus assert call will be simple and most readable.


//try to lock file
$this->assertEquals(true, $lock->acquire(),'ERROR[1]: Result of function acquire() not correct!'. PHP_EOL);
/*
Copy link
Owner

Choose a reason for hiding this comment

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

Why did you commit code that is commented out?

Copy link
Author

Choose a reason for hiding this comment

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

Actually Git do it in automatic way after i add Travis CI to my repository. And i sow this so late after i do a lot of commits.

unit-test.php Outdated
@@ -0,0 +1,107 @@
<?php
Copy link
Owner

Choose a reason for hiding this comment

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

I assume this file doesn't needed anymore?

Copy link
Author

Choose a reason for hiding this comment

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

yes, you are right

@ivancoff
Copy link
Author

ivancoff commented Nov 2, 2018

Hello, "Currently test doesn't cover locking functionality" - yes, i know. At the moment i have some issues with checking file LOCK in Linux system. And my tests always end with errors. So i still going to complete tests for more complex test.

@ivancoff
Copy link
Author

ivancoff commented Nov 5, 2018

hello. i updated test file

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

Successfully merging this pull request may close these issues.

None yet

2 participants