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

Error in AbstractPhysicalQuantityTest::getTestUnitOfMeasure #63

Closed
pierpaolocira opened this issue Dec 5, 2016 · 3 comments
Closed

Comments

@pierpaolocira
Copy link
Contributor

pierpaolocira commented Dec 5, 2016

Hi,
I think there is an error in the abovementioned function (related to the MockBuilder behaviour).

I'm trying to write a new test function, related to the following function declared into the AbstractPhysicalQuantity (see #62)

public static function isUnitDefined($name) {
    	$units = static::getUnitDefinitions();
    	foreach ($units as $unit) {
    		if ($name === $unit->getName() || $unit->isAliasOf($name)) {
    			return true;
    		}
    	}
    	return false;
    }

Following the existing code, I tried to create the related unit test also adding a new unit. This is the only important part of the function to reproduce the error:

public function testIsUnitDefined(){
    	$newUnit = $this->getTestUnitOfMeasure('noconflict', ['definitelynoconflict']);
    	Wonkicity::addUnit($newUnit);
    	$this->assertTrue(Wonkicity::isUnitDefined("noconflict"));    	
    	$this->assertTrue(Wonkicity::isUnitDefined("definitelynoconflict"));    	
    }

The first assert is correct, but not the second one.

I made several test to inestigate on the error... and I saw that if you run (into AbstractPhysicalQuantity) a $unit->getName() or a $unit->getAliases() you will see the expected values.

So the problems seems to be linked to the isAliasOf() method.

I'm running on a PHP 5.5.36 environment.

Hope this helps.

@pierpaolocira
Copy link
Contributor Author

Hi, in the aforementioned pull request (#64) I implemented an alternative method to getTestUnitOfMeasure() (namely getTestUnitOfMeasureSafe()) as a workaround for this issue in the unit tests.
This method can be removed when this issue is closed with a "real" solution (instead of my workaround).
I hope this is accepted.

@triplepoint
Copy link
Member

I think #65 should fix this (though it's a little cumbersome). The travis tests are running right now, if they pass I'll merge that, and you should be able to back out the workaround you made in #64.

@triplepoint
Copy link
Member

Fixed with #65

pierpaolocira added a commit to pierpaolocira/php-units-of-measure that referenced this issue Feb 6, 2017
triplepoint added a commit that referenced this issue Jul 26, 2017
Possible implementation for #62 and temporary workaround for #63
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

No branches or pull requests

2 participants