oliverdavies.uk/content/node.c8fc7878-eaaa-4d15-bc74-954abfe0e1a7.json
2025-05-11 20:02:12 +01:00

100 lines
No EOL
4.1 KiB
JSON

{
"uuid": [
{
"value": "c8fc7878-eaaa-4d15-bc74-954abfe0e1a7"
}
],
"langcode": [
{
"value": "en"
}
],
"type": [
{
"target_id": "daily_email",
"target_type": "node_type",
"target_uuid": "8bde1f2f-eef9-4f2d-ae9c-96921f8193d7"
}
],
"revision_timestamp": [
{
"value": "2025-04-16T14:12:59+00:00"
}
],
"revision_uid": [
{
"target_type": "user",
"target_uuid": "b8966985-d4b2-42a7-a319-2e94ccfbb849"
}
],
"revision_log": [],
"status": [
{
"value": true
}
],
"uid": [
{
"target_type": "user",
"target_uuid": "b8966985-d4b2-42a7-a319-2e94ccfbb849"
}
],
"title": [
{
"value": "Assertions aren't just for tests"
}
],
"created": [
{
"value": "2024-05-08T00:00:00+00:00"
}
],
"changed": [
{
"value": "2025-04-16T14:12:59+00:00"
}
],
"promote": [
{
"value": false
}
],
"sticky": [
{
"value": false
}
],
"default_langcode": [
{
"value": true
}
],
"revision_translation_affected": [
{
"value": true
}
],
"path": [
{
"alias": "\/daily\/2024\/05\/08\/assertions-arent-just-for-tests",
"langcode": "en"
}
],
"body": [
{
"value": "\n <p>If you've written or seen automated tests in PHP, you'll have seen lines like this:<\/p>\n\n<pre><code class=\"php\">self::assertTrue(FALSE);\n<\/code><\/pre>\n\n<p>But, did you know assertions can be used outside of tests.<\/p>\n\n<p>PHP has an <code>assert()<\/code> function that can be used anywhere.<\/p>\n\n<p>For example, if I had this code:<\/p>\n\n<pre><code class=\"php\">$node = Node::load(1);\n\nassert($node instanceof NodeInterface);\nassert($node-&gt;bundle() === 'page');\n<\/code><\/pre>\n\n<p>I know <code>$node<\/code> is a node with the correct bundle type and I can continue.<\/p>\n\n<p>I've made my assumptions explicit.<\/p>\n\n<p>If <code>$node<\/code> is not the correct type or returns an unexpected bundle, the assertion will fail and an Exception will be thrown.<\/p>\n\n<p>I think this is better than assuming or hoping the values are as you expect, and it also makes the intent of the code much easier to see and understand.<\/p>\n\n<p>If you haven't tried <code>assert()<\/code> before, give it a try.<\/p>\n\n ",
"format": "full_html",
"processed": "\n <p>If you've written or seen automated tests in PHP, you'll have seen lines like this:<\/p>\n\n<pre><code class=\"php\">self::assertTrue(FALSE);\n<\/code><\/pre>\n\n<p>But, did you know assertions can be used outside of tests.<\/p>\n\n<p>PHP has an <code>assert()<\/code> function that can be used anywhere.<\/p>\n\n<p>For example, if I had this code:<\/p>\n\n<pre><code class=\"php\">$node = Node::load(1);\n\nassert($node instanceof NodeInterface);\nassert($node-&gt;bundle() === 'page');\n<\/code><\/pre>\n\n<p>I know <code>$node<\/code> is a node with the correct bundle type and I can continue.<\/p>\n\n<p>I've made my assumptions explicit.<\/p>\n\n<p>If <code>$node<\/code> is not the correct type or returns an unexpected bundle, the assertion will fail and an Exception will be thrown.<\/p>\n\n<p>I think this is better than assuming or hoping the values are as you expect, and it also makes the intent of the code much easier to see and understand.<\/p>\n\n<p>If you haven't tried <code>assert()<\/code> before, give it a try.<\/p>\n\n ",
"summary": null
}
],
"feeds_item": [
{
"imported": "2025-04-16T14:12:59+00:00",
"guid": null,
"hash": "6be3e710df2ce66a5d47787fde5a3e20",
"target_type": "feeds_feed",
"target_uuid": "90c85284-7ca8-4074-9178-97ff8384fe76"
}
]
}