Skip to content

Commit

Permalink
Added tests for the ip_resolve config.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmorell committed Mar 1, 2024
1 parent 4d970d3 commit 25f4ef6
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/CurlSenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Rollbar;

use ReflectionClass;
use ReflectionException;
use Rollbar\Payload\Level;
use Rollbar\Senders\CurlSender;

class CurlSenderTest extends BaseRollbarTest
{
Expand All @@ -26,4 +29,43 @@ public function testCurlError(): void
)
);
}

/**
* This test will fail if the {@see CurlSender::$ipResolve} property is renamed or removed.
*/
public function testIPResolve(): void
{
$sender = new CurlSender([
'ip_resolve' => CURL_IPRESOLVE_V4,
]);
self::assertSame(CURL_IPRESOLVE_V4, self::getPrivateProperty($sender, 'ipResolve'));

$sender = new CurlSender([]);
self::assertSame(CURL_IPRESOLVE_V4, self::getPrivateProperty($sender, 'ipResolve'));

$sender = new CurlSender([
'ip_resolve' => CURL_IPRESOLVE_V6,
]);
self::assertSame(CURL_IPRESOLVE_V6, self::getPrivateProperty($sender, 'ipResolve'));

$sender = new CurlSender([
'ip_resolve' => CURL_IPRESOLVE_WHATEVER,
]);
self::assertSame(CURL_IPRESOLVE_WHATEVER, self::getPrivateProperty($sender, 'ipResolve'));
}

/**
* Returns the value of a private property of an object.
*
* @param object $object The object from which to get the private property.
* @param string $property The name of the private property to get.
* @return mixed
* @throws ReflectionException If the object or property does not exist.
*/
private static function getPrivateProperty(object $object, string $property): mixed
{
$reflection = new ReflectionClass($object);
$property = $reflection->getProperty($property);
return $property->getValue($object);
}
}

0 comments on commit 25f4ef6

Please sign in to comment.