Skip to content

Conversation

@localheinz
Copy link
Contributor

@localheinz localheinz commented Jul 12, 2018

This PR

  • uses more appropriate assertions

$output = ob_get_clean();

$this->assertEmpty($output);
$this->assertSame('', $output);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably better to compare with an empty string, as

$this->assertEmpty('[]');

will pass.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could check strlen() also, but this is fine imo.

$jsonEncoder = new Json();
$encodedTrace = $jsonEncoder->encodeTraces([[$span]]);
$this->assertEquals($expectedPayload, $encodedTrace);
$this->assertJsonStringEqualsJsonString($expectedPayload, $encodedTrace);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This assertion will also give a more helpful error message when it fails.

]);

$this->assertEquals(self::BAGGAGE_ITEM_VALUE, $context->getBaggageItem(self::BAGGAGE_ITEM_KEY));
$this->assertSame(self::BAGGAGE_ITEM_VALUE, $context->getBaggageItem(self::BAGGAGE_ITEM_KEY));
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about this change. assertSame gives me the feeling I am comparing objects and not the value of the string which is what we aim to test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jcchavezs

I think it depends on whether we care that a string value is returned, or would be fine, for example if an object were returned that could be casted to string.

Not sure, what do you think?

Personally, I prefer to be as strict as possible, but I'm aware you know much more about this project than I do!

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with José here; being strict on types in tests when we just want a string-ish value could lead to brittleness later. Probably not in baggage items, but as a general philosophy I'd rather go that way. Kind of like accepting interfaces ... we want to get back something that acts like a string, it shouldn't be important what the actual implementation is.

Copy link
Contributor

@chuck chuck left a comment

Choose a reason for hiding this comment

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

The json comparison, and empty string check, look good to me. The rest, unless there's a reason that we really care about type of those arguments, I think are not necessary.

@localheinz
Copy link
Contributor Author

@chuck @jcchavezs

No problem, will adjust later when I’m back at my computer.

@localheinz localheinz changed the title Fix: Use strict and more appropriate assertions Fix: Use more appropriate assertions Jul 14, 2018
@pawelchcki pawelchcki self-requested a review July 23, 2018 09:45
Copy link
Contributor

@pawelchcki pawelchcki left a comment

Choose a reason for hiding this comment

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

Looks good !

Copy link
Contributor

@chuck chuck left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@chuck chuck merged commit c6946eb into DataDog:master Jul 25, 2018
@localheinz localheinz deleted the fix/assertion branch July 25, 2018 18:25
@localheinz
Copy link
Contributor Author

Thank you, @chuck!

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.

4 participants