<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Moxio - Medium]]></title>
        <description><![CDATA[Moxio about software development, design, information managment and the infrastructure industry - Medium]]></description>
        <link>https://medium.com/moxio?source=rss----3bdb0f300dbf---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Moxio - Medium</title>
            <link>https://medium.com/moxio?source=rss----3bdb0f300dbf---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 15:27:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/moxio" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The power of subtle links: Balancing aesthetics, usability, and accessibility in modern design…]]></title>
            <link>https://medium.com/moxio/the-power-of-subtle-links-balancing-aesthetics-usability-and-accessibility-in-modern-design-e2af71aa345c?source=rss----3bdb0f300dbf---4</link>
            <guid isPermaLink="false">https://medium.com/p/e2af71aa345c</guid>
            <category><![CDATA[product-design]]></category>
            <category><![CDATA[accessible-design]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[accessibility]]></category>
            <dc:creator><![CDATA[Riska Veldhoven]]></dc:creator>
            <pubDate>Mon, 17 Mar 2025 07:49:35 GMT</pubDate>
            <atom:updated>2025-03-17T07:49:35.270Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*97vXelXQLzF6OtY6w-otRg.png" /></figure><h3>The power of subtle links: Balancing aesthetics, usability, and accessibility in modern design systems</h3><p>In a mature design system like <a href="https://moxio.com/blog/the-power-of-subtle-links-in-modern-design-systems/">Moxio’s</a>, every detail is carefully considered to create a seamless and accessible user experience. Even the smallest elements, such as subtle links, play a crucial role in enhancing usability without compromising aesthetics and accessibility.</p><p>In this blog we take the subtle link as an example of how you can creatively challenge yourself as a product designer to create the best user experience within the constraints of a Design System.</p><p><strong>The case</strong> <br>Our applications for information management, mostly used in the world of infrastructure, are built on ‘tables’. These tables contain a lot of hyperlinks, with different links for each cell. The links help the user to dive, layer for layer, deeper into the asset/data structure. <br>You can imagine that these links can be quite overwhelming and too prominent when using a regular hyperlink with blue color and underline. It would easily undermine the hierarchy of the application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/0*PGmxD0HJQIsQUamm.png" /></figure><p><em>Regular hyperlinks in tables can easily undermine the hierarchy of an interface.</em></p><p>We can consider a secondary link, but this would still be too prominent:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/0*qsQ_j8IqtpY2T6YU.png" /></figure><p><em>A secondary link would still be too prominent.</em></p><p>A subtle link would do the job in terms of hierarchy, but… they have no distinguishing element compared to regular text in their default state and there is no sign whatsoever (beside context) that the text is clickable at all. So subtle links as we know them would not be very accessible for our users either:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/0*fRMz3-pg1qLWTj3y.png" /></figure><p><em>Subtle links as we know them are not very accessible either.</em></p><p><strong>The challenge</strong> <br>So the challenge is to design a subtle link, that can be thoughtfully integrated into our interfaces, maintaining visual hierarchy while remaining accessible to all users. How can we strike the right balance between aesthetics, functionality, and inclusivity? Let’s explore the nuances.</p><p><strong>Accessibility: The key to inclusive subtle links</strong> <br>Subtle links can contribute to an elegant user experience, but it is essential not to overlook accessibility. People with visual impairments or color blindness may struggle to recognize regular subtle links. Let’s take the following into account:</p><p><strong>Consistency within the design system: why it matters</strong> <br>A good design system requires consistency, and subtle links are no exception. By adopting a standardized approach, designers can provide a unified user experience. Consider the following:</p><p><strong>User behavior and psychology: what makes subtle links effective</strong> <br>The human brain is trained to recognize patterns and anticipate interactions. If links are too subtle, users may easily overlook them. Some insights from UX research include:</p><p><strong>Conclusion: Striking the balance between Form and Function</strong> <br>While wrapping our head around all the above, we found out that the underline can be styled separate from the text color. This gave us the chance to style subtle links réally subtle and balance discoverability, hierarchy, and accessibility.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/0*CZA4x42OYL0r_1ic.png" /></figure><p><em>Accessible and still subtle links, within the visual hierarchy of other elements.</em></p><p>In the meantime, we have implemented a subtle link where the underline is a lighter color / shade than the text itself. This ensures that links remain easily identifiable without overwhelming the surrounding content. By maintaining a clear visual distinction while respecting the overall design hierarchy, our solution offers a more user-friendly and accessible alternative to other existing approaches.</p><p>By combining creativity with best practices, your design system will remain not only visually appealing but also functional and inclusive for everyone.</p><p><em>Originally published at </em><a href="https://moxio.com/blog/the-power-of-subtle-links-in-modern-design-systems/"><em>https://moxio.com</em></a><em> on March 14, 2025.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2af71aa345c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/moxio/the-power-of-subtle-links-balancing-aesthetics-usability-and-accessibility-in-modern-design-e2af71aa345c">The power of subtle links: Balancing aesthetics, usability, and accessibility in modern design…</a> was originally published in <a href="https://medium.com/moxio">Moxio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ignoring bulk change commits with git blame]]></title>
            <link>https://medium.com/moxio/ignoring-bulk-change-commits-with-git-blame-5d50835e45c2?source=rss----3bdb0f300dbf---4</link>
            <guid isPermaLink="false">https://medium.com/p/5d50835e45c2</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[legacy-code]]></category>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[code-style]]></category>
            <dc:creator><![CDATA[Arnout Boks]]></dc:creator>
            <pubDate>Thu, 17 Oct 2019 07:04:56 GMT</pubDate>
            <atom:updated>2019-10-17T07:04:27.785Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MoSo1CCugpxVTpYenLBbEw.png" /><figcaption>Let `git blame` ignore one specific commit</figcaption></figure><p>A long-standing objection to making bulk changes to code using automated tools (e.g. to conform to a given code style) is that it clutters the output of git blame. With git 2.23, this does not have to be the case anymore! In this post I will start by explaining the value of git blame and how commits with style changes in bulk can be problematic. If you already understand this problem and just want a solution, you can directly skip to the <a href="https://www.moxio.com/blog/43/ignoring-bulk-change-commits-with-git-blame#git-2.23-to-the-rescue">new features git 2.23 has to offer</a>.</p><h3>Putting changes into context</h3><p>A characteristic feature of legacy code is that it’s often not clear why it operates the way that it does. Some of the original developers may have left or have been reassigned to another project, documentation is virtually nonexistent, and the few remaining developers do not remember all the details anymore. For example, one day you might stumble upon the follow piece of code:</p><pre>&lt;?php <br>function describeBottles(int $amount = 42): string {<br>    return &#39;There are &#39; . $amount . &#39; bottles of cider on the wall.&#39;; <br>}</pre><p>Despite being an artificial example, this code already raises some questions. Why is the default amount of bottles being described 42? And why do we describe bottles of cider? Bottles of beer would be a more customary alternative, right? Still these choices were probably made for a good reason; it’s just that we don’t know that reason.</p><p>It would be good if the reasoning behind these choices was documented using comments. However, as happens with legacy code, this is not the case. How can we still find out the motivation behind the current state of the code? A version control system such as <a href="https://git-scm.com/">git</a> (you use version control, right?) may be helpful here. If you write <a href="https://chris.beams.io/posts/git-commit/">good commit messages</a> that focus on the <em>why</em> rather than the <em>how</em>, you might be able to distill the context from there. We only need to find which commit made a given change.</p><p>The command (or if you prefer a more positive mindset) can be helpful here. It shows, for each line in a file, which commit made the last change to that line, along with its timestamp and author:</p><pre>$ git blame describeBottles.php <br>^8206b47 (Jane Doe   2019-04-21 09:41:20 +0200 1) &lt;?php <br>b589bf1e (John Smith 2019-07-03 14:42:46 +0200 2) function describeBottles(int $amount = 42): string { <br>2c386e07 (A.N. Other 2019-09-18 16:58:24 +0200 3) return &#39;There are &#39; . $amount . &#39; bottles of cider on the wall.&#39;; <br>^8206b47 (Jane Doe   2019-04-21 09:41:20 +0200 4) }</pre><p>From this output we can see that line 3 was last changed by ‘A.N. Other’ in commit 2c386e07. If we lookup the details for that commit we may find out why this function describes bottles of cider rather than beer:</p><pre>$ git show 2c386e07 <br>commit 2c386e07b72041af1e0c2f827ac31357829429dd <br>Author: A.N. Other &lt;a.n.other@example.com&gt; <br>Date: Wed Sep 18 16:58:24 2019 +0200 </pre><pre>    Change drink </pre><pre>    Extensive user testing has shown that our customers like <br>    cider better than beer. </pre><pre>    Jira: BOT-123 </pre><pre>diff --git a/describeBottles.php b/describeBottles.php <br>index ef2b0fd..9336895 100644 <br>--- a/describeBottles.php <br>+++ b/describeBottles.php <br>@@ -1,5 +1,5 @@ <br>&lt;?php function describeBottles(int $amount = 42): string { <br>-    return &#39;There are &#39; . $amount . &#39; bottles of beer on the wall.&#39;; <br>+    return &#39;There are &#39; . $amount . &#39; bottles of cider on the wall.&#39;; <br>}</pre><p>Bingo! We have found the exact commit in which we swapped beer for cider, and more importantly: we know why. We even have a link to a Jira ticket where we can find more information. Perhaps it contains the full user testing results, providing us with even more context. This makes git blame an absolute life saver in legacy projects.</p><h3>The problem: bulk changes</h3><p>The team behind the describeBottles-function has always used their own coding standards, with opening braces on the same line and &#39;CRLF&#39; line endings. One day they decide to adopt the <a href="https://www.php-fig.org/psr/psr-2/">PSR-2</a> coding style guide that has become popular in the PHP community. Luckily there are tools like <a href="https://github.com/FriendsOfPHP/PHP-CS-Fixer">PHP-CS-Fixer</a> and <a href="https://github.com/squizlabs/PHP_CodeSniffer/wiki/Fixing-Errors-Automatically">phpcbf</a> to automatically convert the whole codebase to the new standard. There are similar tools for almost all other programming languages.</p><p>Now the team has one huge commit with style changes in their repository. It touches every line without altering the meaning or intent of the code. If we would now use git blame to find the background for a line of code, the ouput would be:</p><pre>$ git blame describeBottles.php <br>df0ee6b0 (Regina Phalange 2019-09-26 16:51:58 +0200 1) &lt;?php df0ee6b0 (Regina Phalange 2019-09-26 16:51:58 +0200 2) function describeBottles(int $amount = 42): string <br>df0ee6b0 (Regina Phalange 2019-09-26 16:51:58 +0200 3) { <br>df0ee6b0 (Regina Phalange 2019-09-26 16:51:58 +0200 4) return &#39;There are &#39; . $amount . &#39; bottles of cider on the wall.&#39;; <br>df0ee6b0 (Regina Phalange 2019-09-26 16:51:58 +0200 5) }</pre><p>As we can guess, the last commit that touched line 4 does not give us any useful context anymore:</p><pre>$ git show df0ee6b0 <br>commit df0ee6b006ee0f90cccc18b71ced290f6cae18d9 (HEAD -&gt; master) <br>Author: Regina Phalange &lt;r.phalange@example.com&gt; <br>Date: Thu Sep 26 16:51:58 2019 +0200</pre><pre>    Fix line endings </pre><pre>diff --git a/describeBottles.php b/describeBottles.php <br>index 17f0657..d9c9f99 100644 <br>--- a/describeBottles.php <br>+++ b/describeBottles.php <br>@@ -1,5 +1,5 @@ <br>-&lt;?php -function describeBottles(int $amount = 42): string <br>-{ <br>-    return &#39;There are &#39; . $amount . &#39; bottles of cider on the wall.&#39;; <br>-} <br>+&lt;?php <br>+function describeBottles(int $amount = 42): string <br>+{ <br>+    return &#39;There are &#39; . $amount . &#39; bottles of cider on the wall.&#39;; <br>+}</pre><p>Because these bulk changes render git blame useless, many teams refrain from applying automated style changes of this magnitude. That means they have to live with either a coding standard that they would rather not have, or with a codebase that does not follow their standards.</p><h3>Git 2.23 to the rescue!</h3><p>To limit the impact of such ‘unimportant’ bulk commits, git 2.23 adds a new option to git blame. Using , one can specify a commit to be ignored by git blame. Lines changed by the ignored commit will be attributed to the previous commit touching that line instead. This means that even after our bulk style change, we can get back a meaningful context for the &#39;real&#39; changes to our function:</p><pre>$ git blame --ignore-rev df0ee6b0 describeBottles.php <br>^8206b47 (Jane Doe   2019-04-21 09:41:20 +0200 1) &lt;?php <br>b589bf1e (John Smith 2019-07-03 14:42:46 +0200 2) function describeBottles(int $amount = 42): string <br>b589bf1e (John Smith 2019-07-03 14:42:46 +0200 3) { <br>2c386e07 (A.N. Other 2019-09-18 16:58:24 +0200 4) return &#39;There are &#39; . $amount . &#39; bottles of cider on the wall.&#39;; <br>^8206b47 (Jane Doe   2019-04-21 09:41:20 +0200 5) }</pre><p>Note how even line 3, which was added by the ignored commit, is attributed to commit b589bf1e, which originally added the brace on the line above.</p><p>When multiple bulk commits were added over time, it takes quite some effort to add a --ignore-rev for each of them in order to get a &#39;clean&#39; output for git blame. Luckily, git also provides a way to make this easier on us. In your repository, create a file to hold commit hashes of commits to be ignored by git blame. Naming this file .git-blame-ignore-revs seems to be a common convention.</p><pre>$ cat .git-blame-ignore-revs <br># Conversion to PSR-2 code style <br>237de8a6367a88649a3f161112492d0d70d83707 <br># Fix line endings <br>df0ee6b006ee0f90cccc18b71ced290f6cae18d9</pre><p>The file should contain the full (40 char) commit hashes. Lines starting with a # are considered comments and can be used to explain what makes the given commit(s) unimportant. Now we can call git blame with the <a href="https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-fileltfilegt">--ignore-revs-file</a> option to ignore all these commits at once:</p><pre>$ git blame --ignore-revs-file .git-blame-ignore-revs describeBottles.php</pre><p>The .git-blame-ignore-revs can be versioned inside the repository, so that all developers can use (and maintain) the same list of ignored commits. To avoid typing the extra option with every command, we can set the <a href="https://git-scm.com/docs/git-config#Documentation/git-config.txt-blameignoreRevsFile">blame.ignoreRevsFile</a> configuration variable:</p><pre>$ git config blame.ignoreRevsFile .git-blame-ignore-revs</pre><p>This causes git to automatically ignore the commits specified in that file for every call to git blame. If you stick to the .git-blame-ignore-revs naming convention you can even set this configuration variable globally, so that it applies to all your repositories, each with their own .git-blame-ignore-revs file. Be aware however that git currently gives an error when this setting is configured globally but a repository has no .git-blame-ignore-revs file yet. I hope that this is considered a bug and will be fixed in an upcoming version.</p><p>Another limitation to be aware of is that platforms like GitHub and GitLab do not yet support files with commits to ignore for the ‘blame’-button in their user interface. It would be awesome if they added such a feature soon.</p><p>One last thing: be aware that you need at least version 2.23 of git to use these new features. On the <a href="https://git-scm.com/downloads">git downloads page</a> you can find out how to obtain the latest git for your platform. But even if you cannot upgrade yet for some reason, you can already start building a .git-blame-ignore-revs file with commits you would like to hide from git blame. That way you can hit the ground running when it&#39;s time to upgrade.</p><h3>Summary</h3><p>Git 2.23 contains an absolute game changer that is not even mentioned in the <a href="https://github.blog/2019-08-16-highlights-from-git-2-23/">release highlights</a>. Fear of polluting the git blame output no longer has to be a blocker for applying style changes in bulk: these commits can now be ignored. You can even share a list of ignored commits with your entire team. So go ahead and switch over to that new coding standard; git won&#39;t hold you back anymore.</p><p><em>Originally published at </em><a href="https://www.moxio.com/blog/43/ignoring-bulk-change-commits-with-git-blame"><em>https://www.moxio.com</em></a><em> on October 16, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d50835e45c2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/moxio/ignoring-bulk-change-commits-with-git-blame-5d50835e45c2">Ignoring bulk change commits with git blame</a> was originally published in <a href="https://medium.com/moxio">Moxio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mutation testing in PHP]]></title>
            <link>https://medium.com/moxio/mutation-testing-in-php-656cbab3bf4f?source=rss----3bdb0f300dbf---4</link>
            <guid isPermaLink="false">https://medium.com/p/656cbab3bf4f</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[mutation-testing]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Arnout Boks]]></dc:creator>
            <pubDate>Thu, 18 Jul 2019 13:16:04 GMT</pubDate>
            <atom:updated>2019-07-18T13:35:13.760Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I spent an afternoon experimenting with <em>mutation testing</em> in PHP. In this post I would like to share the background, the main idea of mutation testing, and the lessons I’ve learned from it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MM2MfxFwWD5TMibwWu2gBQ.jpeg" /></figure><h3>Moxio Academy</h3><p>At <a href="https://www.moxio.com/">Moxio</a> we regularly schedule a <em>Moxio Academy</em> session. That means we put our normal work aside for an afternoon to learn something new or experiment with the latest technologies. You can choose any topic, as long as it benefits your personal development and thus your role at the company. There are just a few rules:</p><ul><li>You have to decide on a topic and announce it in advance. This is meant to improve synergy within the team: maybe someone already knows a lot about the topic and has some resources to recommend. If multiple people want to learn about the same thing, maybe they can combine their efforts and learn together.</li><li>You must create a plan for how to approach your topic. This does not have to be very extensive, just a rough sketch is enough. The idea is that this forces you to focus your learning efforts rather than just reading random resources without any sense of a general direction.</li><li>You should work towards some kind of deliverable. Ideally this is something that can be shared with the rest of the team: a tool, wiki article, some proof-of-concept, blogpost or lunch-and-learn presentation. Again this helps to focus the process, to have some concrete end result, and to spread the acquired knowledge within the team.</li></ul><p>We usually conclude the afternoon together to present our process and results, and (for those who want) have a pizza.</p><h3>Mutation testing</h3><p>At the latest Moxio Academy I wanted to experiment with <em>mutation testing</em> in PHP. I had already heard about mutation testing and <a href="https://infection.github.io/">Infection</a> as a tool to do so a few times, but never got around to play with it hands-on. This seemed like a good opportunity.</p><p>In essence, <em>mutation testing</em> is a way of measuring the quality of a test suite. A tool generates a number of copies ( <em>mutants</em>) of your source code under test, but modifies each of them in a small way. These small modifications are basically just errors that you as a programmer could have made, such as replacing a &lt; with a &lt;=. A high-quality testsuite would detect these modifications ( <em>kill the mutant</em>) by failing one or more tests. In a suboptimal test suite it might happen that the tests remain green despite the modification to the source code. In such a case we speak about an <em>escaped mutant</em>. These present an opportunity to improve the test suite by adding a test that fails in the presence of the given modification. The <em>Mutation Score Indicator</em> (MSI, the percentage of mutants detected by the test set) provides a metric for the quality of the test suite.</p><p>My plan was to apply Infection to one of our internal libraries. I picked this library because of its high (line-based) code coverage, which would imply a high-quality test suite. Therefore I wondered what ‘leaks’ Infection could still find in it. The idea was to convert the escaped mutations found by Infection to new tests, working towards a PR to increase the MSI of the project as the main deliverable. This blog post wasn’t part of the original plan, but arose as an extra way of sharing some of the lessons learned along the way.</p><h3>Lessons learned</h3><h4>Mutation testing is awesome!</h4><p>My main takeaway was that mutation testing can really help you to improve your test suite. Even on a project with 96% line coverage, Infection found multiple scenarios that were not actually covered by the test suite.</p><p>One simplified example of this is the following. Suppose we have a function to generate a description for the amount of bottles of beer on the wall:</p><pre>&lt;?php<br>function describeBottles(int $amount = 99): string {<br>    return $amount . &#39; bottles of beer on the wall&#39;;<br>}</pre><p>We could already have a test for this function like this:</p><pre>&lt;?php<br>class DescribeBottlesTest {<br>    public function testDescribesTheAmountOfBottlesOfBeer() {<br>        $this-&gt;assertSame(&#39;42 bottles of beer on the wall&#39;, describeBottles(42));<br>    }<br>}</pre><p>At first sight it may seem that this fully tests the function, and indeed the function shows up with all lines covered in a code coverage report. However, our tests do not check the default value for the argument. This means that some behavior of our function, i.e. that by default it describes 99 bottles, is not verified. Infection can uncover this when it produces a mutation like:</p><pre>12) /tmp/bottles.php:2    [M] DecrementInteger<br><br>--- Original<br>+++ New<br>@@ @@<br>&lt;?php<br>- function describeBottles(int $amount = 99): string {<br>+ function describeBottles(int $amount = 98): string {<br>      return $amount . &#39; bottles of beer on the wall&#39;;<br>  }</pre><p>Here the DecrementInteger mutator has decremented an integer literal occurring in the source code, an error we could have made ourselves if we hit the wrong key on our keyboard. This would currently go unnoticed, but we can fix that by adding a test like:</p><pre>&lt;?php<br>class DescribeBottlesTest {<br>    public function testDescribes99BottlesByDefault() {<br>        $this-&gt;assertSame(&#39;99 bottles of beer on the wall&#39;, describeBottles());<br>    }<br>}</pre><p>Other untested aspects commonly found by Infection were exception messages and some uncovered paths through complex logic. I added tests or assertions for most of these. For the logic, this is also a sign that the (cyclomatic/N-path) complexity is too high. Those pieces of code should be refactored, but I scheduled that for later.</p><p>On the first Infection run, without any changes to the test suite, it produced a 89% MSI. This is already quite good, but with some additions to the test suite I managed to raise the MSI to 93%.</p><h4>‘False positives’</h4><p>Getting the MSI much higher proved to be difficult though. Sometimes escaped mutants had changes to parts of the code that are nonessential details. In our view, these details do not constitute relevant behavior and are not part of the ‘contract’ of that unit. Why are they in the code then? Well, sometimes they have to be due to syntactical constraints. Take for example the following piece of code that may throw an exception:</p><pre>&lt;?php<br>// ...<br>try {<br>    $database-&gt;executeSql(&quot;...&quot;);<br>} catch (DuplicateDatabaseKeyException $e) {<br>    throw new UserAlreadyExistsExeption(&quot;User $username already exists&quot;, 0, $e); <br>}</pre><p>As explained in a <a href="https://www.moxio.com/blog/34/best-practices-for-php-exception-handling">previous blog post</a>, we think it is important that exceptions are thrown at the right level of abstraction. This requires catching and re-throwing exceptions like in the above code snippet. In that post, I also mentioned that we want to maintain the connection with the root cause by setting the $previous-parameter of the new exception. Due to PHP&#39;s syntax this requires one to also provide the $code-parameter, which we do not really use. We usually set it to 0 (the default), but honestly couldn&#39;t care less about its value.</p><p>Now the same DecrementInteger mutator could come along and produce this mutation:</p><pre>53) /tmp/exception.php:289   [M] DecrementInteger<br><br>--- Original<br>+++ New<br>@@ @@<br>  } catch (DuplicateDatabaseKeyException $e) {<br>-     throw new UserAlreadyExistsExeption(&quot;User $username already exists&quot;, 0, $e); <br>+     throw new UserAlreadyExistsExeption(&quot;User $username already exists&quot;, -1, $e); <br>  }</pre><p>This mutation will not get caught by our test suite (because we do not assert the code of produced exceptions), so the mutant will escape. In this case we do not care however. We don’t expect our test suite to detect this, as (to us) the mutated code is just as fine as the original. We could add assertions for the exception code, but that would just be extra work without yielding extra value.</p><p>I think this is something to be aware of when doing mutation testing. Not all escaped mutants are necessarily bad. For each of them you have to ask yourself the question “Would it be bad if I made this ‘error’ in my code?”. If the answer is no, don’t bother about the escaped mutant.</p><h4>What test to add?</h4><p>One of the main difficulties when trying to kill a mutant was figuring out what kind of test to add. Just from seeing a changed line in the code it is not always clear how to write a test that would fail on the given line. This was further amplified by the fact that the codebase I worked with was written by a colleague, and I did not know it inside out yet.</p><p>I learned that the HTML code coverage report generated by PHPUnit can be of tremendous help here. If you hover over a covered line of code there, it shows you which tests cover that line. This way you can lookup which tests already exercise the mutated line of code. The test you want to add to kill the mutant is probably a variation of one of them. This reduces your problem to analyzing these ‘example’ tests and reasoning about what you could change in them to fail when the mutation is present.</p><h4>It improves your code too</h4><p>Not only the test suite got some updates during my experiments with mutation testing; the production code improved as well. Sometimes the mutants generated by Infection were actually better than the original version! One such case looked somewhat like this:</p><pre>&lt;?php<br>class SomeStore {<br>    public static function createWithInMemoryDatabase(): self {<br>        $database = $database ?? new SqliteDatabase(&#39;:memory:&#39;);<br>        // ...<br>    }<br>}</pre><p>Among the generated mutations there was one that removed the $database ?? null coalesce operator. This is actually an improvement, as the null coalesce operator is useless here! At the start of the function, $database is always null, so the operator always resolves to its right-hand side, creating a new database. This code was an artifact from a moment when the method was named differently and allowed injecting a custom database through a $database parameter. Now that parameter has been removed, we can get rid of the null coalesce as well. While other static analysis tools could have found this dead code as well, at least Infection brought it to our attention.</p><p>Another example where the mutant turned out to be better was the removal of a trim() function. At that spot in the code there could never be any significant or problematic whitespace. The trim()-call thus was unnecessary and could be removed.</p><h3>Conclusion</h3><p>Once you’ve had some practice with mutation testing, it can really help with improving both your test suite and code. Infection is straightforward to setup and use, and makes it fairly simple to get started in PHP. Just keep in mind that not all escaped mutants are a problem and blindly striving for 100% MSI does not add value. Try it out, and let me know what your experiences are!</p><p><em>Originally published at </em><a href="https://www.moxio.com/blog/39/mutation-testing-in-php"><em>https://www.moxio.com</em></a><em> on July 18, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=656cbab3bf4f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/moxio/mutation-testing-in-php-656cbab3bf4f">Mutation testing in PHP</a> was originally published in <a href="https://medium.com/moxio">Moxio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a design system — from project to process — Moxio]]></title>
            <link>https://medium.com/moxio/creating-a-design-system-from-project-to-process-moxio-7e05787926b5?source=rss----3bdb0f300dbf---4</link>
            <guid isPermaLink="false">https://medium.com/p/7e05787926b5</guid>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[product-development]]></category>
            <category><![CDATA[product-design]]></category>
            <category><![CDATA[process]]></category>
            <dc:creator><![CDATA[Annemiek Scheele]]></dc:creator>
            <pubDate>Thu, 18 Apr 2019 07:35:42 GMT</pubDate>
            <atom:updated>2019-10-17T12:13:37.957Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P3DQ-vSd5L3FgR5bPU1jvA.jpeg" /></figure><h3>Creating a design system — from project to process — Moxio</h3><p>When we started building a design system we approached it as a project, but as we all know a design system should be always evolving. Therefore it would be a never-ending project. And a never ending project.. that’s something nobody really wants. In this blog I will share how we started our design system as a project, moved on to a process, what the process is and how this works for us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qIGKUE61UcU3DiNu_3Ve4g.png" /></figure><h3>Why was it a project at first</h3><p>At first we approached it as a project because we weren’t sure of the outcome or where it would exactly go. Step by step the design system became what it is now.<br>We couldn’t build the components from scratch because we had to deal with existing styling and legacy. Within the project we did sub-projects, such as replacing all the icons and buttons. But other cases were much more process bound: Identify the component, check the level of legacy and pick the approach to replace it.<br>In my <a href="https://www.moxio.com/blog/24/building-a-design-system-the-challenges-we-face">previous blog</a> you can find more about why and how we started to build a design system.</p><h3>The tipping point</h3><p>We had no clear end point for the design system as a ‘project’ but we had a roadmap that said ‘Convert the core elements’ and ‘Reduce custom styling and merge generic styling from applications into one shared bundle’. So when most of our components were reviewed and renewed and we saw applications and client specific styling shrink, we got the feeling the end for this so-called project was near. Also the design system started being used in two major projects and where normally templates were leading, design system components were now used to rapidly implement new UI’s.</p><h3>Setting up the process</h3><p>Now that teams were using the design system to create new views from scratch, we were getting a lot of questions, such as: “Why can’t this widget do this?”, “Is there an option for that?” etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ufSmZJduBeJ3M4icl5k0MQ.png" /></figure><p>We went from existing components that needed to be reviewed and renewed, to question driven design and development. This required something different than our project-based approach.<br>In one project, we combined developing a new product and developing new design system components. This failed because of sprint pressure. We where making decisions on the fly, which wasn’t good for the quality of the developed components. So we needed to make a change.</p><h3>Team</h3><p>We already had a core team responsible for the development of the design system and which held a weekly meeting. But the team was focused on the project and we were mainly pushing our own agenda. Different members of the team got requests for changes and were figuring out how to deal with them. We needed to change our mindset. The design system team wasn’t only there anymore to create a design system but also to improve components, develop new components on request, help and share.</p><h3>A structured way to get input and to act on the input</h3><p>Requests came from everywhere: on slack, one on one, on product development boards, after demoing a feature etc. All this communication needed to be channeled and structured in a better way.</p><p>While we were running our design system as a project, we had been using a Trello board with 4 columns:</p><ul><li>Backlog</li><li>Issues</li><li>In progress</li><li>Fixed.</li></ul><p>To better facilitate the process, rather than a project, we changed the columns to:</p><ul><li>Backlog</li><li>Inbox</li><li>Specs</li><li>Design</li><li>Front-end</li><li>Review</li><li>Implementation</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LD5OTYm0gqbM_rQS.png" /></figure><h4>Inbox</h4><p>Although the first column is Backlog the process starts at the Inbox. Everyone in our company adds their requests to the inbox column. During the week everyone can report or request a new component, additional functionality for a component, an error, inconsistencies, etc. On Monday morning the design team goes through all the cards that have been added to the Inbox. We discuss the request: is it something we want, we need, what is the priority and what needs to be done. Cards go from the Inbox to the Backlog (low prio), Specs. (yes we want this), Front-end (this is a minor change or a bug) or are rejected (this is not something we want).</p><h4>Specs.</h4><p>Specs, specs, specs. For a solid design system in which components are developed for the right reason this is an important step. We’ve already checked if this is something we want but in this column we have to do a more in depth search. Why do we need this, don’t we have an other component already providing these features, what is the core function etc. When the specifications are clear we can start the design.</p><h4>Design</h4><p>With the specifications we start the design of the addition, component or function. The styling and interaction are worked out in this phases.</p><h4>Front-end</h4><p>After the design phase it is sent to front-end. A front-ender picks up the component and develops the component or makes the changes.</p><h4>Review</h4><p>When the styling and front-end development is done, we review the component before it goes to implementation so we can still make changes if this is needed. We check if the component meets its specifications. After the review is done and there is nothing to be changed, it moves to implementation.</p><h4>Implementation</h4><p>Implementation has two sides. First there’s the actual implementation in our applications where the request came from in the first place. Additionally, the functionality is added to and documented, in our component library, so it’s accessible for everyone to use.</p><h4>Backlog</h4><p>As all other backlogs, cards that go here are good ideas but have no priority.</p><h3>Turnaround time and fall back</h3><p>The turnaround time of the process depends on the kind of request. Adding a different type of icon to the confirm widget can be done within a day, while developing a whole new component could take a couple of iterations. We have no strict time frame.</p><p>The development of our applications follow a continuous development process. Most of the time the need for new components starts when concepts are formed or pages and flows are designed. This means there is still enough time to develop the component, or at least the MVP (minimal viable product) of a component before it gets to development. But sometimes there isn’t much time to wait on a new or improved component. In that case we have two options for fallback;</p><ul><li>Use existing items</li><li>Custom (and local) code.</li></ul><p>Both come with the arrangement that when the new components is available, it should replace the previous implementation.</p><h3>How we are rolling after a few months</h3><p>We’ve started this process at the beginning of this year, so we have been using it for a few months now and it’s good to look back on that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xtS6Wf16EBx3bH0u.png" /></figure><h3>Promoting the inbox</h3><p>In the beginning not everyone could find the inbox and most cards were about improvements and issues people from the design system team found, but now most cards in the inbox are from non-design system team members. We’ve promoted the inbox in our monthly company demos, there is a link on the homepage of our component library and when someone sends a question in Slack everyone refers them to the inbox.</p><h3>The process</h3><p>The specs and review step are still a bit underrated. We quite easily decide whether we should take the request in production, send it to the backlog or reject it but we easily step into design or front-end without good specification. This sometimes produces errors and miscommunication, which at the end costs more time to fix. Because the specs are incomplete, missing or too vague the review step is already undermined. This step is mainly being used to ensure code quality at the moment, but it would be good to also review the functionality. These steps feel more like a formality right now, and we have to figure out how we can use these steps better and more efficiently, so they feel like they are actually contributing.</p><h3>People know what they can expect (and that’s important for the design systems foundation)</h3><p>When you need something in a project but it isn’t there, that can be very frustrating. Now with the process we implemented, people know what they can expect. Cards that have been submitted in the inbox are always reviewed on Monday, issues and errors are still handled as soon as possible. We inform people whether we are going to add it to the design system or discard the proposal.</p><h3>Is it a component or a one hit wonder</h3><p>Especially when new things come around, it’s good to realize if it is something we want for the long run. Can we see this concept being used in other views or application, or is it just needed for this one time? Usually when the concept is very complex and heavily relying on it’s context, you shouldn’t make it into a standard design system component. Custom design and development are also a valid option in these cases.</p><p>Still it can be hard to determine this, because you just can’t look into the future and know which features users need or what new innovations developers will create. Having this Monday meeting with the team allows us to take a step back and discuss these things and make the right decision.</p><h3>Conclusion</h3><ul><li>The process is part of the quality assurance of the design system.</li><li>With the process we have integrated the design system even more in our organisation.</li><li>People know what to expect.</li><li>It keeps us from making (bad) decisions on the fly.</li></ul><h3>It’s a living thing</h3><p>The best thing here is that our design system became a living and evolving design system. It hasn’t become a finished project which ends up in the back of a drawer — which I imagine is the fear of anyone working on setting up a design system. People, from all disciplines in our organisation can actively contribute. It’s adopted in the way we work. Even though the process isn’t finalized (will it ever be?) this works for us.</p><p><em>Originally published at </em><a href="https://www.moxio.com/blog/37/creating-a-design-system-from-project-to-process"><em>https://www.moxio.com</em></a><em> on April 15, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e05787926b5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/moxio/creating-a-design-system-from-project-to-process-moxio-7e05787926b5">Creating a design system — from project to process — Moxio</a> was originally published in <a href="https://medium.com/moxio">Moxio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finding memory issues in PHP programs — Part 2]]></title>
            <link>https://medium.com/moxio/finding-memory-issues-in-php-programs-part-2-81d92f13ed9b?source=rss----3bdb0f300dbf---4</link>
            <guid isPermaLink="false">https://medium.com/p/81d92f13ed9b</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[memory-leak]]></category>
            <category><![CDATA[profiling]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Tom den Braber]]></dc:creator>
            <pubDate>Tue, 12 Mar 2019 09:40:40 GMT</pubDate>
            <atom:updated>2019-03-12T09:40:40.525Z</atom:updated>
            <content:encoded><![CDATA[<h3>Finding memory issues in PHP programs — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*AVdDGsKTeEYSw5ig" /></figure><p>The cause of a memory issue is often hard to find. In the <a href="https://www.moxio.com/blog/33/finding-memory-issues-in-php-programs">previous post</a>, we looked at two methods for finding the culprits of a memory issue. In case you missed it, check it out!</p><p>In this post, we will look at another tool for finding memory leaks: <a href="https://github.com/arnaud-lb/php-memory-profiler/">php-memprof</a>, created by Arnaud Le Blanc.</p><h3>Another profiler… why?</h3><p>Each profiler has its own characteristics. In the previous post, we saw that the Xdebug profiler generates a ‘cumulative memory profile’: it shows the sum of all the allocations made by a certain function over the lifetime of the program. This makes the generated profile sometimes hard to interpret. With the profiles generated by Xdebug, you cannot see if the memory is already released at the time the profile is generated. However, such a situation could very well indicate a memory leak. php-memprof is made to fill in this gap. It provides information which can be used to find whether a function ‘leaks’ memory.</p><h3>Setting up php-memprof</h3><p>The installation of php-memprof can be done using PECL (pecl install memprof), or manually. After downloading the source, make sure you have <a href="http://judy.sourceforge.net/">libJudy</a> installed and run the following commands in the source directory.</p><pre>phpize<br>./configure <br>make<br>make install</pre><p>Make sure to load the extension (set extension=memprof.so in your php.ini or run your script with php -dextension=memprof.so my_script.php). For my own analyses, I use <a href="https://github.com/tomdenbraber/php-memprof-docker">a Docker image</a> that has the extension already installed and loaded by default.</p><p>Note that running Xdebug and php-memprof alongside will not work. To be able to run php-memprof, Xdebug has to be disabled.</p><h3>Running example</h3><p>As our running example, we will use a simple array-based cache implementation. The store function is an excellent example of (valid) code that keeps memory allocated, even after its termination.</p><pre><strong>&lt;?php</strong> <br>class ArrayBasedCache {<br>	private $cache = [];<br><br>	public function store(string $key, $data) {<br>		$this-&gt;cache[$key] = $data;<br>	}<br><br>	public function has(string $key) {<br>		return isset($this-&gt;cache[$key]);<br>	}<br><br>	public function get(string $key) {<br>		if ($this-&gt;has($key) === false) {<br>			throw new LogicException(&quot;Tried to get &#39;$key&#39; from cache, but it does not exist. has(\$key) should be checked first!&quot;);<br>		}<br>		return $this-&gt;cache[$key];<br>	}<br><br>	public function clear() {<br>		$this-&gt;cache = [];<br>	}<br>}</pre><h3>Using php-memprof</h3><p>To signal php-memprof that it should start profiling, the memprof_enable() function has to be called. After the call to this function, php-memprof starts tracking memory allocations. This implies that memory allocated <em>before</em> memprof_enable() was called will not be taken into account.</p><p>The information that php-memprof gathered can be dumped using one of the following functions:</p><ul><li>memprof_dump_array() dumps the information in an array format</li><li>memprof_dump_callgrind(resource $stream) dumps the information to the given $stream in the callgrind format, which can be analysed using <a href="https://kcachegrind.github.io/html/Home.html">KCachegrind</a> or <a href="https://sourceforge.net/projects/qcachegrindwin/">qCachegrind</a> (as shown in the previous post)</li><li>memprof_dump_pprof(resource $stream) dumps the information to the given $stream in the <a href="https://github.com/google/pprof">pprof</a> format</li></ul><p>Let’s run the following code:</p><pre><strong>&lt;?php</strong> <br>$cache = new ArrayBasedCache;<br><br>memprof_enable();<br>printf(&quot;A:\n%s\n&quot;, json_encode(memprof_dump_array(), JSON_PRETTY_PRINT));<br><br>$cache-&gt;store(&quot;a&quot;, 123);<br><br>printf(&quot;B:\n%s\n&quot;, json_encode(memprof_dump_array(), JSON_PRETTY_PRINT));<br>memprof_disable();</pre><p>The JSON-encoded output of this script is as follows:</p><p>A:</p><pre>{<br>    &quot;memory_size&quot;: 0,<br>    &quot;blocks_count&quot;: 0,<br>    &quot;memory_size_inclusive&quot;: 0,<br>    &quot;blocks_count_inclusive&quot;: 0,<br>    &quot;calls&quot;: 1,<br>    &quot;called_functions&quot;: []<br>}</pre><p>B:</p><pre>{<br>    &quot;memory_size&quot;: 103,<br>    &quot;blocks_count&quot;: 3,<br>    &quot;memory_size_inclusive&quot;: 479,<br>    &quot;blocks_count_inclusive&quot;: 5,<br>    &quot;calls&quot;: 1,<br>    &quot;called_functions&quot;: {<br>        &quot;ArrayBasedCache::store&quot;: {<br>            &quot;memory_size&quot;: 376,<br>            &quot;blocks_count&quot;: 2,<br>            &quot;memory_size_inclusive&quot;: 376,<br>            &quot;blocks_count_inclusive&quot;: 2,<br>            &quot;calls&quot;: 1,<br>            &quot;called_functions&quot;: []<br>        }<br>    }<br>}</pre><p>The first thing to note is that the dumped structure is recursive. The top-level fields indicate the data from the main program, that is the code that is executed outside any function.<br>In the called_functions field, we can see the callees from the overarching context. For each of these called functions, the same fields are present again.<br>Let&#39;s go over all the fields that we see in the output to find out what they mean:</p><ul><li>memory_size: the number of bytes allocated from the current context;</li><li>blocks_count: the number of memory blocks allocated from the current context;</li><li>memory_size_inclusive: the number of bytes allocated by the function itself plus all the memory that was allocated by any of the callees of the current context;</li><li>blocks_count_inclusive: same as for memory_size_inclusive, but expressed in blocks;</li><li>calls: the number of times this function was called from the overarching context;</li><li>called_functions: a dictionary with the keys being function-names and the fields being all the fields that are in this table. This field represents the call-stack.</li></ul><p>We can see that the A-dump does not contain information about the creation of the ArrayBasedCache itself: this call happened <em>before</em> the enabling of php-memprof and is therefore not taken into consideration. As the A-dump is generated immediately after enabling php-memprof, we see that the dump has no information about any allocated memory.<br>The B-dump shows that ArrayBasedCache::store was called once from the &#39;main&#39; program. We can also see that ArrayBasedCache::store has a memory_size of 376 bytes, eventhough its execution was already terminated by the time the B-dump was generated. These bytes are still in memory because the store method added data to the local $cache field, and did not remove it.</p><p>Let’s see another example:</p><pre><strong>&lt;?php</strong> <br>$cache = new ArrayBasedCache;<br><br>memprof_enable();<br><br>$cache-&gt;store(&quot;a&quot;, 123);<br>$cache-&gt;clear();<br><br>json_encode(memprof_dump_array(), JSON_PRETTY_PRINT);<br>memprof_disable();</pre><p>and its output:</p><pre>{<br>    &quot;memory_size&quot;: 103,<br>    &quot;blocks_count&quot;: 3,<br>    &quot;memory_size_inclusive&quot;: 103,<br>    &quot;blocks_count_inclusive&quot;: 3,<br>    &quot;calls&quot;: 1,<br>    &quot;called_functions&quot;: {<br>        &quot;ArrayBasedCache::store&quot;: {<br>            &quot;memory_size&quot;: 0,<br>            &quot;blocks_count&quot;: 0,<br>            &quot;memory_size_inclusive&quot;: 0,<br>            &quot;blocks_count_inclusive&quot;: 0,<br>            &quot;calls&quot;: 1,<br>            &quot;called_functions&quot;: []<br>        },<br>        &quot;ArrayBasedCache::clear&quot;: {<br>            &quot;memory_size&quot;: 0,<br>            &quot;blocks_count&quot;: 0,<br>            &quot;memory_size_inclusive&quot;: 0,<br>            &quot;blocks_count_inclusive&quot;: 0,<br>            &quot;calls&quot;: 1,<br>            &quot;called_functions&quot;: []<br>        }<br>    }<br>}</pre><p>After calling $cache-&gt;clear(), all items in the cache are removed. The allocation that was done by $cache-&gt;store(...) is thereby deleted, and we can see in the dump that there is indeed no memory allocated by ArrayBasedCache::store at the time the dump is made.</p><p>As you can imagine, the array output will become very large for larger programs. For small, isolated scripts the memory_dump_array works fine. For larger programs, I find it way more useful to look at a visualisation of the output of the memory_dump_callgrind function.</p><h3>Wrapping up</h3><p>In this post, we looked at another profiler, which approaches memory profiling from a different angle as compared to the Xdebug profiler we looked at last time. This two-part series is meant to help you find the causes of memory issues faster and with a more structured process. Several techniques, like logging memory usage, using profilers, and profile analysis tools have been discussed. Do you miss an important technique that should have been discussed in this series? <a href="http://www.twitter.com/moxio">Let us know</a>!</p><p>Photo by <a href="https://unsplash.com/photos/91LGCVN5SAI?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Daan Mooij</a> on <a href="https://unsplash.com/search/photos/leak?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></p><p><em>Originally published at </em><a href="https://www.moxio.com/blog/36/finding-memory-issues-in-php-programs-part-2"><em>www.moxio.com</em></a><em> on February 21, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81d92f13ed9b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/moxio/finding-memory-issues-in-php-programs-part-2-81d92f13ed9b">Finding memory issues in PHP programs — Part 2</a> was originally published in <a href="https://medium.com/moxio">Moxio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your design system is up and running — what’s next?]]></title>
            <link>https://medium.com/moxio/your-design-system-is-up-and-running-whats-next-f1988814d98f?source=rss----3bdb0f300dbf---4</link>
            <guid isPermaLink="false">https://medium.com/p/f1988814d98f</guid>
            <category><![CDATA[user-research]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[card-sorting]]></category>
            <dc:creator><![CDATA[Emilie Dack]]></dc:creator>
            <pubDate>Tue, 26 Feb 2019 15:13:53 GMT</pubDate>
            <atom:updated>2019-02-26T15:13:52.988Z</atom:updated>
            <content:encoded><![CDATA[<h3>Your design system is up and running — what’s next?</h3><p>Big steps have been made since we first started with our design system project. It has become a well-oiled process and everyone is familiar with the tool. We were curious to know how the rest of the team felt about working with it. Time for some internal research! Through a series of interviews, card sorting sessions and tests we learned how to make our design system a tool the whole team would love to use.</p><h3>Atomic design</h3><p>At Moxio, we have been developing our own design system over the past year. If you haven’t heard of the expression, this is a popular method to catalogue all components and elements used in an application. It’s a handy tool for both designers and developers to work together and maintain consistency in UI as products evolve. It’s essentially a library of elements used in a digital product, often with guidelines describing how to use any given element, which we call style guides.</p><p>Check out Annemiek’s comprehensive <a href="https://medium.com/moxio/building-a-design-system-the-challenges-we-face-99225ca9d8a7">blog</a> about it from December 2017 — she explains our need for a design system and how we went about to set one up. This project has been going strong, as we add components and write style guides, making it easier for our teams to grab an element to use in any given context.</p><p>However, as our system grew, we realised we needed to re-evaluate how we categorised elements. Our list of style guides was growing longer by the day. We had been using Brad Frost’s structure of Atomic Design — where elements are sorted according to atomic, molecular and organic categories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J1DYo81W--9O1bnJ.jpg" /></figure><p>Basically, this meant that:</p><ul><li>Very small elements which could not be reduced to anything smaller, were sorted under the category “atoms”</li><li>Larger elements which were combinations of atoms, were sorted under “molecules”</li><li>Even larger elements, which were combinations of (atoms and) molecules, were labelled “organisms”</li><li>We used templates to show examples of all variations of a widget in greater detail</li></ul><p>We assumed this would be clear to everyone, but we’d never really checked if this was true. Since we had so many elements being documented, our menu navigation became very long — it felt cluttered. Our design system team decided to review the current method of categorising these elements: how could we sort them into clear, distinct categories? Did everyone else at Moxio understand and like to use the atomic design principles? How could we guarantee ease of use over time? It was time for some internal user research!</p><h3>Research setup</h3><p>We used a combination of methods to figure out what the rest of the team needed: interviews, card sorting sessions and validating findings.</p><p>We wanted to involve the whole team in this exercise, so that everyone felt comfortable using the design system — make it a tool people want to use in their daily workflow, something we all share responsibility for. Our aim was to uncover our teammates’ mental models, to define a new conceptual model of how to organise information in our design system.</p><h3>What is a mental model?</h3><p>A mental model describes the different ways of thinking, of structuring information, that individuals all have. It’s a personal interpretation of a thing or a situation. That’s part of the reason why assumptions can’t be trusted — they’re based on your own mental model, your own perspective based on your personal experience. We didn’t know if the Atomic Design principles matched people’s internal representation of how elements were sorted — was there a way to organise them which would meet (most) people’s mental schematic?</p><h3>What is a conceptual model?</h3><p>A conceptual model is the actual representation of the interface of a product — where the mental model is internal, individual, the conceptual model is the physical interface, which should match the user’s mental model. For more information about this, check out uxmag’s <a href="https://uxmag.com/articles/the-secret-to-designing-an-intuitive-user-experience">article</a>.</p><p>To find out more about how our people think and what makes them tick, we started with interviews to explore the current understanding and experience of the style guides.</p><h3>Interviews</h3><h4>Why interviews?</h4><p>To uncover mental models, we started out by, well, simply talking to each other. We didn’t know how people had been using the design system, let alone how they felt about searching for style guides… We had given demos of the system, but how were people using it? What did they like about it? What could be improved? What kind of information did they need from style guides? To do this, we started with some short interviews with teammates who had already some experience using the style guides.</p><p>We chose these people because we needed to do a sanity check — was this what people needed? How did they view and use the style guides? Based on these findings and insights from seasoned users, we would be able to define how to continue our internal research into categorising the elements.</p><h4>Findings</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8OFZjdJAL4qbfYl2.jpg" /></figure><p>It turned out that the style guides as such were quite useful already, with some small improvements in terms of content. For instance, people wanted clearer use case examples of <strong>when to use</strong> a given component, and <strong>when not to use</strong> it.</p><p>This feedback brought up a discussion in our design system team — should we also spend time documenting examples of what <strong>not </strong>to do? Rather than focusing on negative examples, we decided to spend extra time developing writing guidelines for the style guides themselves. We defined a set of rules for tone of voice, how to organise the content and how to describe the context of use. A few layout changes were made to improve readability.</p><p>The preliminary findings showed us that our teammates were interested in contributing to making the overall design system easier to use and more valuable for them. This helped us to decide how to continue — by using card sorting methods, we hoped to involve many people in depth and uncover patterns of expectations for where to find elements. We moved on to next the part of our internal research: open card sorting sessions.</p><h3>Card sorting</h3><h4>Open card sorting</h4><p>We decided to go for an open card sorting exercise, in which no predefined categories are set. We had been using “Atoms — Molecules — Organisms” as main categories, following Brad Frost’s Atomic Design principles. Our design system team liked the use of larger main categories, but we weren’t convinced that these names made it clear where each element belonged. One of the goals for this exercise was to check our gut feeling with other teammates, while defining a clear subcategorization for the elements themselves.</p><p>A total of 9 individual card sorting sessions were held, with people both familiar and unfamiliar with the design system. Those with the least experience with the design system served as a control group, to verify that the categorisation could be understood by new colleagues in the future.</p><p>Most components and elements currently in the design system were printed out on small cards. That gave us 56 cards, which is around the advised maximum of cards to use in an open card sort. Any more would make the session too complex and would result in participant fatigue, something you can read more about in Optimal Workshops <a href="https://www.optimalworkshop.com/101/card-sorting#cardCount%20">guidelines</a>. Fatigue was the opposite of what we wanted to achieve — we wanted people to enjoy using the design system, not get fed up thinking about it!</p><p>If you do have more than 60 elements to sort into cards, pick the most important ones and stick to between 40–60 cards. Once you have a clear structure, it’ll be easier to sort the remaining elements not included in the exercise.</p><p>Participants were asked to sort them into categories of their choosing and then name the categories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lrjQ-Bv8laqYYIpw.jpg" /></figure><p>After a few sessions, some categories already started to appear. However, there seemed to be a big difference in the starting point of participants. We considered them as being split over two clans, which we named “Purists” and “Contextualists”:</p><ul><li><strong>“Purists”</strong> — those who chose a categorisation based on a pure definition of an element — what it is, what it is made of. Such definitions are generally stable and development-driven</li><li><strong>“Contextualists”</strong> — those who preferred a categorisation based on functionality of an element — what it does, when it is used. Such definitions rely on the context of use and can be multi-faceted. It is user-centred and gives more meaning to a component.</li></ul><p>Since components can sometimes be used in different contexts, most context-oriented participants eventually got stuck trying to place one multi-faceted element in a single category.</p><p>The problem “contextualists” faced could be traced back to a wish to sort elements into a recognisable pattern based on general definitions, as well as wanting to tell something more about the underlying relationship between elements — how they are to be used, how they work together. This uncovered a hidden need to see how elements relate to each other. This is a need we could cater for in the content pages rather than the menu navigation.</p><p>Another challenge lies in the context of use of the style guide library, our design system. There are at least two distinct usages for the design system:</p><ul><li><strong>Search for a specific component. </strong>The developer or designer knows which component they need. This implies previous knowledge and experience using the design system. Such a categorisation is not prone to change.</li><li><strong>Search for a component for a specific problem. </strong>The developer or designer does not know which component to use. They know what some functional requirements are. In that case, they might look for an element that provides feedback about the status of an object after it has been edited.</li></ul><p>A categorisation based on context is more “human” than a development-driven categorisation, which is systematic and based on solid facts — not subjective experience. However, there are a couple of caveats:</p><ul><li><strong>No single function for all elements. </strong>A single functional definition of each element is not always possible, meaning one element could fit into several categories based on context of use.</li><li><strong>Definitions are subjective, as well as subject to change over time. </strong>The success of such a categorisation relies heavily on everyone having the same mental model with regards to naming and sorting elements. For instance, does a “key-value input” belong with other inputs, or in a section for “Forms” (which says a lot more about when key-values are used)?</li><li><strong>Prioritising functionalities. </strong>This last one is related to the first point: once we’ve defined all (current) possible functionalities of an element, how do we distil the one most important functionality of an element?</li></ul><p>Although very interesting on a cultural level, the contextualist point of view was not the most prominent group in the research. Out of our 9 sessions, 3 participants were clearly contextual in their way of thinking. Others hinted at this but decided to use a more purist approach. This allowed them to define a single categorisation based on the structure of the element, rather than all possible uses for it.</p><h4><strong>Data and decisions</strong></h4><p>It seemed a context-based definition would be difficult to apply and to keep using in the long run. People who started out enthusiastically sorting elements according to context of use, were soon left stranded in the complexity of wanting to fit everything in single categories. Would this be reflected in the data?</p><p>After a total of 9 sessions, we saw enough similarities and patterns emerge that we decided to tally the results. We’re a small team of 15 and, by then, had spoken with most users of the design system with the interviews and the card sorting sessions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5jjKNoquSO8qapXm.jpg" /></figure><p>The categories of each session were entered in a spreadsheet. This gave us an initial raw number of 47 categories. Of these 47 categories, 9 were contextually oriented: ‘Feedback,’ ‘Status,’ ‘Workflow,’ ‘Browsing,’ ‘Helping tools,’ ‘Verbal,’ ‘Non-verbal, Mutable or Choices,’ and ‘Immutable.’</p><p>In some of these examples, the naming shows a distinct subjectivity and interpretation, the different meanings people apply to digital elements — highly interesting from a user researcher’s point of view, although challenging to apply for a more general categorisation. For this reason, we chose to let go of this contextual approach. Instead, we would move forward with the “purist” logic of categorising elements based on what an element is, from a technical point of view.</p><p>Despite the many categories, we did find similarities in the number of times an element appeared in any given section. Patterns started to emerge. To sort them out into distinguishable clusters, we merged categories which used similar names for similar purposes.</p><p>In doing so, a clearer categorisation started to emerge: 3 main categories, with 12 subsections — including 2 sections named ‘Other’ for elements which did not fit into a unique category.</p><h3>It’s elementary, my dear Watson!</h3><p>Do you recall the Atomic Design Principles we had been using until now? While most participants appreciated the hierarchical breaking down into 3 categories, the terms Atoms, Molecules and Organisms did not make the sorting logic immediately clear. Although people with a basic level of understanding of physics will know the differences between these 3 elements — the translation to digital components is what gave this distinction a learning curve. It made the entire exercise seem a little…<em>too much</em>.</p><p>We didn’t want a learning curve. We hoped to achieve a level of simplicity which would make our Design system a logical, easy-to-use tool that enriched everyone’s workflow. The same meaning could be conferred by using a naming convention such as “Small — Medium — Large” (although <em>what is Medium?</em> and <em>what is Large?</em> could still be a subjective issue).</p><p>We renamed it “Basics — Components — Views,” hoping this would be clearer, as these names had been made up by participants during the sessions. It was essentially the same kind of categorisation as the atomic design principles, but we hoped this semantic change would make it clear what each category collected.</p><ul><li><strong>“Basics”</strong> referred to all the base elements, often related to style: typography, icons, colours…</li><li><strong>“Components” </strong>collected all other elements, from simple to more complex. Things like Inputs, Buttons, Bars were gathered under this header.</li><li><strong>“Views” </strong>consisted of larger application elements. During the card sorting, it became clear that such a category was necessary, with sections being named “Application XL” and “Externals” to describe near-cmplete parts of the application.</li></ul><p>We hoped this naming convention would make it easier to sort the elements into the newly defined subsections than when following Brad Frost’s Atomic Design principles.</p><h3>Testing</h3><p>Using the newly defined subsections and their three main categories, we asked a couple of colleagues to participate in a closed card sorting exercise. A closed card sorting is one where we give predefined categories and ask participants to sort the cards into those categories. Our hope was that the resulting categorisation matched that resulting from the open card sorting research. This went much faster than the previous sessions.</p><p>There was, however, some doubt as to the naming of two main categories. “Views” conveyed a subjective meaning, ‘how you look at things,’ which did not make it immediately clear what should fit in this section. It was either too abstract or too subjective, so we knew we would need to change it for something which conveyed in practical terms, what this section collected.</p><p>To clarify this, we changed the term “Views” to “Modules”, as this seemed to convey the correct meaning more successfully. It also fit better in the developer vocabulary, so we hoped it would be more easily recognised. The series was now: Basics — Components — Modules.</p><p>Despite the initial confusion over naming conventions, the overall results of the closed card sorts were satisfying: participants could easily and quickly perform the card sort. The categorisation into subsections was clear and easily recognisable.</p><h3>Final thoughts</h3><p>All in all, this has been an insightful research experiment. By involving the rest of the team in this process, they took charge and explained what they felt was logical.</p><p>Some participants’ natural instincts were to label elements based on the context of use — this shows how comfortable they were with the elements themselves. This logic would be interesting for a definitive list of components, one which would not be subject to change. For Moxio, a company with various product offerings, where elements can be expanded over time, this contextual definition logic did not seem the most fruitful. Still, it was an interesting and insightful line of thought to uncover.</p><p>It was nice to see that the design system itself was already very much engrained in the collective mind. People knew what it was and what it included. They had already been using it for some time. The findings were all the richer for it. We also learned that there was a need to know how elements related to each other, to improve findability. This came up during the initial interviews and the card sorting sessions — this was the need that was being responded to by the contextualists. How does one element relate to another?</p><p>One instance of this, which we came across earlier this week, is the relationship between checkboxes and tables. Checkboxes are presented as standalone components under a subsection named Inputs. In the style guides for checkboxes, we included an example of the input in a table cell — yet this was not included in the table style guide. The design system team discussed this and decided to move the example to the Table style guide and simply refer to it in the checkbox style guide. We could do this in the introduction, making sure the description included this contextual information, and use a section for “Related components” which displays in-page links.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/0*OSDT7QRm89RJpglY.jpg" /></figure><p>Our new sorting logic also meant a new design for the menu — applying an accordion effect made navigation in the design system a lot easier. We included a search input: people had been Ctrl+F’ing to get to the right component, so it was added as a real feature in the navigation.</p><p>The purpose of this internal research was to re-evaluate our current organisation of content in our design system, to see if any changes were needed to make the system more future-proof and accessible. By holding open card sort sessions, we uncovered hidden mental models and got a peek into people’s expectations. This allowed us to define a new categorisation, test it and see mostly positive results. We’re not sure if everything will stay in the same category, but it’s good enough to test it in real life.</p><p>So, for now, we have a new design system structure — let’s put it to practice and see how it holds up!</p><p><em>Originally published at </em><a href="https://www.moxio.com/blog/35"><em>www.moxio.com</em></a><em> on February 10, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1988814d98f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/moxio/your-design-system-is-up-and-running-whats-next-f1988814d98f">Your design system is up and running — what’s next?</a> was originally published in <a href="https://medium.com/moxio">Moxio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Best practices for PHP exception handling]]></title>
            <link>https://medium.com/moxio/best-practices-for-php-exception-handling-fc7848a98132?source=rss----3bdb0f300dbf---4</link>
            <guid isPermaLink="false">https://medium.com/p/fc7848a98132</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-design]]></category>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Arnout Boks]]></dc:creator>
            <pubDate>Thu, 10 Jan 2019 15:31:01 GMT</pubDate>
            <atom:updated>2019-01-10T15:58:17.201Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dS9UtZR5EydvCPeqxLCMow.jpeg" /></figure><p>Handling errors or other non-’happy path’ situations is essential when creating robust PHP applications. While <a href="http://php.net/manual/en/language.errors.php">errors</a> were the main construct to do so in PHP 4, <a href="http://php.net/manual/en/language.exceptions.php">exceptions</a> have been around since PHP 5. They should nowadays be considered the main mechanism for handling alternative or exceptional paths. It seems that these alternative paths still don’t always get the attention they deserve, though.</p><p>Proper exception handling takes quite some effort, but will eventually result in a much more stable application. A sensible exception handling strategy makes it clear what exceptions should be expected (and thus handled!) at a given point in the code. Moreover it will maintain the encapsulation and abstraction you carefully applied to your object-oriented design. Last but not least, it should make debugging a breeze.</p><p>In this post, I would like to introduce you to the set of best practices we have adopted at <a href="https://www.moxio.com/home">Moxio</a> over the years. We have found these to work very well for us, but keep in mind that they are <em>our</em> best practices; your mileage may vary. The following guidelines are aimed at PHP code, but the basic principles behind them will also (with some translations) work for similar languages.</p><h3>Types of exceptions</h3><p>We make a distinction between the two top-level types of exceptions that the PHP <a href="http://php.net/manual/en/book.spl.php">SPL library</a> defines. These are <a href="http://php.net/manual/en/class.logicexception.php">LogicException</a> and <a href="http://php.net/manual/en/class.runtimeexception.php">RuntimeException</a>. The interpretation of these two types in literature varies. We however attach the following meaning to them:</p><ul><li>A LogicException is an exception that should require a fix or change in code. With &#39;code&#39; we do not only mean source code, but any content managed by a developer. This includes configuration and database contents that are not maintained by an end user of the system. A LogicException is mainly an internal guard or assertion. In perfectly written and wired code one should never occur.</li><li>A RuntimeException is an exception that might also occur in code that is written and configured &#39;perfectly&#39;. Such an exception may be caused by input from the end user, or an error in (the communication with) an external system. When a RuntimeException is thrown, it should not require a fix in the code. If the exception ends up uncaught however, we should add some code to handle it. This may mean logging the error, using a fallback strategy, reporting the error to the user, or a combination thereof.</li></ul><p>Note that this interpretation differs from the generic perception in Java, where a RuntimeException is what we would call a LogicException. Furthermore, in our standards we classify all exceptions into either one of these categories. We do not create exceptions as a direct subclass of Exception.</p><h3>Exceptions as part of the function signature</h3><p>We see the possible variants of RuntimeException that can be thrown or bubbled up from a function as part of the contract of that function. That means such exceptions should be annotated on the function using @throws.</p><p>If the function is part of the implementation of an interface, that interface should specify that (a supertype of) the exception in case could be thrown. Annotating such an exception also on the implementation is not necessary. A function that implements an interface should never throw a runtime exception not declared on the interface. Such a case would be a violation of the <a href="https://www.tomdalling.com/blog/software-design/solid-class-design-the-liskov-substitution-principle/">Liskov Substitution Principle</a>.</p><p>On the contrary, we consider the different types of LogicException to not be part of the contract of a function. Of course we assume a perfect implementation, but at the same time we know there can always be an error somewhere. Therefore a LogicException can always be expected and unexpected at the same time. Hence annotating it using @throws is not desirable. See also &#39;catching exceptions&#39; below.</p><h3>Creating exception subclasses</h3><p>Under these guidelines, creating a hierarchy of subtypes under RuntimeException is very desirable. The more specific the exceptions we throw (and annotate as part of our contract), the more granular we can handle them. Subclasses of LogicException however are not necessary. These are not part of the contract of a function anyway.</p><h3>Catching exceptions</h3><p>To us, a RuntimeException is a <em>checked</em> exception. When such an exception can be thrown from a function, the calling function needs to either catch that exception or declare it as a possible exception from itself using @throws. Catching a runtime exception is a good idea when the calling code can sensibly handle the exception, or when it can re-throw it at a better level of abstraction (see <a href="https://www.moxio.com/blog/34/best-practices-for-php-exception-handling#rethrowing">further down</a>). At least it is important to think about the handling of these exceptions when calling a function that might throw them.</p><p>A logic exception should never be caught, at least not based on the type LogicException or a subclass thereof. These exceptions should never occur in a correct implementation. It therefore does not make sense to try to handle them along the line. Instead, the logic that triggered the exception should be fixed.</p><p>At some point it may be necessary to catch <em>all</em> exceptions, including both variants of RuntimeException and LogicException. As we require PHP 7 at minimum, we do this using Throwable in our catch-clause, not Exception. Constructs like this are exclusively meant for component entry points, and should never make assumptions about the specific cause or character of the exception. Such code will therefore never contain specific error handling logic. Instead, they are a generic catch-all for logging or reporting the error, or giving the end user feedback that something went wrong.</p><p>Sometimes a catch-all like this is also used for cleaning up resources or closing open connections. A finally-block is often better in such situations, especially if the exception is re-thrown at the end of the catch-block.</p><h4>Special case: debug info</h4><p>One valid reason to catch a LogicException anyway is to augment it with extra debugging information that was not available deeper in the call stack. In such a case we directly throw a new LogicException with the extra data, and the original exception in $previous. We preferably catch such an exception based on the most generic type possible. This may be a common base class or <em>marker interface</em> for all LogicExceptions that can occur in the given piece of code.</p><p>The alternative for such a catch would be to pass the debug information on to the callees that eventually produce the error. We prefer not to do so if such information is only used for passing it into an exception.</p><h3>Throwing a new exception after catching</h3><p>After catching an exception, it is of course possible to throw a new exception. Indeed, for sensible exception handling this is needed more than one may expect. Just make to always set the $previous-parameter of the new exception to the original (caught) exception. This ensures the the full cause of the exception can still be derived. Because of the order of the Exception constructor parameters it is then often necessary to specify a $code. We don&#39;t use this parameter, so we just set it to 0.</p><h4>Translation to the correct level of abstraction</h4><p>Catching-and-throwing is often necessary to ensure that an exception manifests itself at a suitable level of abstraction. Suppose we have a UserRepositoryInterface that is implemented by a DatabaseUserRepository. The latter stores users in the database, which raises a DuplicateDatabaseKeyException if a user with the given username already exists. According to the rules described earlier we should use @throws to annotate this exception on the interface, but that rightly feels a bit strange. Why would a generic interface, meant to abstract the storage mechanism away, know about a type of exception specific to a database? The solution is to catch the DuplicateDatabaseKeyException within DatabaseUserRepository and throw something like a UserAlreadyExistsExeption in its place. This exception matches the level of abstraction of UserRepositoryInterface: it knows about users, but not how they are persisted. It can therefore added to the signature of that interface without issues.</p><h4>From RuntimeException to LogicException</h4><p>It is very well possible that an exception that was a RuntimeException is at some point converted into a LogicException. This has to do with specific knowledge we have at that point, from which we know that the given exception should not be possible. That knowledge was not available deeper in the <em>call stack</em>.</p><p>To illustrate this, assume we have an XML reader with a method getUniqueTagContents. This method reads the contents of one unique tag from an XML file based on the tag name. A lot of things can go wrong inside such a method: the XML file may be malformed, the given tag may not be present, or it may occur multiple times. These are all examples of a RuntimeException. Without extra knowledge about the origin of the XML (which may be uploaded by a user) and the tag name they can also occur in a perfectly programmed application. But it is possible that we use this method on a piece of XML that we just validated against an XML schema that enforces the existence and unicity of the given tag. In such a situation we know that getUniqueTagContents should not fail. The same applies when we use the method to read a configuration file that we put in VCS ourselves and which we thus fully control.</p><p>In such situations we still have to catch the ‘impossible’ runtime exceptions, as we consider them <em>checked</em>. In this catch-block we then throw a LogicException: this situation should never happen. Of course we save the original exception through the $previous parameter.</p><p>This is a pattern that occurs often. Deep in the <em>call stack</em>, where the bigger picture is not available, many faults are a RuntimeException. As the exception bubbles up (whether translated to another level of abstraction or not), it reaches a point where we know the error should be impossible. At that point it becomes a LogicException. Note that the inverse is not possible: an unexpected error can not suddenly be expected.</p><h3>A grey area</h3><p>The distinction between a RuntimeException and a LogicException is not always 100% clear. There is a grey area where the correct type of exception depends on interpretation and the semantic constract of a function. A few examples to illustrate this:</p><h4>Syntax error in a query</h4><p>A method executeQuery to execute a database query can fail due a syntax error in that query. A first sight this looks like a RuntimeException: we don&#39;t know where the query comes from and thus cannot guarantee its syntactical correctness. On the other hand it would be very strange if user input (or input from another source beyond our control) could lead to a syntax error. That smells of SQL injection. It is therefore very reasonable to state that the code calling executeQuery is responsible for the syntactical correctness of the query. That makes the exception a LogicException. An exemption would be if we were building an application like <a href="https://www.adminer.org/">adminer</a> or <a href="https://www.phpmyadmin.net/">phpMyAdmin</a> where we should expect errors in user-entered SQL queries.</p><h4>Cache item not found</h4><p>Suppose we have a cache class with a method get($key) to retrieve a cache item. Of course it can happen that get is called with a key that does not exist. We assume that we have chose to communicate this via an exception (alternatives would be through the return value or a by-reference parameter). Would such an exception be a runtime or a logic exception?</p><p>The answer probably depends on the other methods on the cache class and how we expect to use these. If the cache has a has method we could demand that a consumer uses that method to check whether a cache item exists before retrieving it with get. In that case a LogicException is reasonable. Depending on the implementation of the cache there may be a tiny chance that a cache item is deleted between the calls to has and get. In such cases even a perfect implementation (which checks existence first) cannot fully prevent the error. The &#39;correct&#39; exception category is not very clear here. For now we tend to use a LogicException for situations with rare edge cases like this.</p><h4>Corrupt data in the database</h4><p>Another grey area is formed by errors that can only occur in case of a corrupted database. From a puristic view this is an example of a RuntimeException, the database being an external factor. On the other side it is undesirable to have to take the possibility of database corruption into account everywhere in the code. This applies all the more if only the application and occasionally a developer or sysadmin writes to the database. A more pragmatic approach is to consider database corruption a LogicException. Chances are that the corrupt data was caused by an implementation error in the application. Anyway, developer or sysadmin intervention is required to manually fix the data.</p><h3>Recap</h3><p>We distinguish checked exceptions that represent inherently ‘unfixable’ situations from unchecked exceptions that represent programming errors. Therefore we know at every point in the code what exceptions we should expect, and thus handle. By catching and re-throwing exceptions we make sure that they are at the proper level of abstraction and thus not break encapsulation. Chaining the original exception using the $previous parameter ensures that no debugging information is lost.</p><p>Are you trying out these practices in your project? <a href="https://twitter.com/moxio">Let us know</a> if they work for you, if there are obstacles you run into, or if you have improvements to these guidelines. We’d love to get your feedback!</p><p><em>Originally published at </em><a href="https://www.moxio.com/blog/34/best-practices-for-php-exception-handling"><em>www.moxio.com</em></a><em> on January 10, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc7848a98132" width="1" height="1" alt=""><hr><p><a href="https://medium.com/moxio/best-practices-for-php-exception-handling-fc7848a98132">Best practices for PHP exception handling</a> was originally published in <a href="https://medium.com/moxio">Moxio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finding memory issues in PHP programs]]></title>
            <link>https://medium.com/moxio/finding-memory-issues-in-php-programs-93cd9a4a9049?source=rss----3bdb0f300dbf---4</link>
            <guid isPermaLink="false">https://medium.com/p/93cd9a4a9049</guid>
            <category><![CDATA[memory-leak]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Tom den Braber]]></dc:creator>
            <pubDate>Fri, 12 Oct 2018 09:37:40 GMT</pubDate>
            <atom:updated>2019-03-12T09:48:16.641Z</atom:updated>
            <content:encoded><![CDATA[<h3>Finding memory issues in PHP programs — Part 1</h3><p>“Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 528384 bytes).” If this error sounds familiar, this post is for you. The problem with this message is that it does not tell you a lot: it does not tell you where all the memory was allocated. Locating the places where a lot of memory is consumed in large and complex systems is not easy. Luckily, there are some tools available which can help finding the problematic code. In this post, we will cover two methods for finding places in your program where a lot of memory is allocated.</p><h3>Running example</h3><p>We will be using the following code as our running example. The purpose of the code is finding Nemo. There are two functions: one that reads a file in which Nemo could be located, and the other which tries to find a line of which the content is equal to ‘nemo’. The problem with this snippet is that it sometimes consumes too much memory. Not always, but with certain files, the program crashes.</p><pre>&lt;?php<br>function fetch_data_from_file(string $file_path) : iterable {<br>    $resource = fopen($file_path, &#39;r&#39;);<br>    $lines = [];<br>    while (($line = fgets($resource)) !== false) {<br>        $lines[] = trim($line);<br>    }<br>    return $lines;<br>}</pre><pre>function finding_nemo(string $filepath) : int {<br>    $lines = fetch_data_from_file($filepath);<br>    foreach ($lines as $line_number =&gt; $line) {<br>       if ($line === &quot;nemo&quot;) {<br>           return $line_number;<br>       }<br>    }<br>    return -1; //nemo not found<br>}</pre><pre>finding_nemo(&quot;the_sea.txt&quot;);</pre><p>All the techniques and tools described are not needed to solve this issue (can you already spot the problem?), but it enables us to see how those tools and techniques work in practice.</p><h3>memory_get_usage()</h3><p>PHP has two functions which can tell you something about the memory usage of you program: memory_get_usage and memory_get_peak_usage. <br>memory_get_usage only gives insight in <em>how much</em> memory is in use at the moment of the function call. memory_get_peak_usage returns the maximum number of bytes allocated by the program until the function call. Both of these functions take one boolean argument: $real_usage. If $real_usage is set to true, memory_get_usage returns the total amount of memory that is actually allocated from the operating system, but some of it might not (yet) be in use by your program. If it is set to false, it returns the number of bytes which PHP has requested (and received) from the operating system, and which is actually in use by the program. The following statement always holds: memory_get_usage(true) &gt;= memory_get_usage(false). Memory is requested in blocks, which are not fully used all of the time.</p><p>An advantage of using these functions is that they are really easy to use. One of the possible ways of finding your memory leak is scattering calls to memory_get_usage all over your code, and logging its output. You can then try to find a pattern: where does the memory usage increase?<br>A drawback of these functions is that their use is limited, as they do not provide insight in which functions or classes are using all that memory.</p><p>Let’s use these functions to get an idea of where our current problem might reside. In the example below, I use marker characters like ‘A’, ‘B’, etc. to be able to track a log entry back to a location in the code. Another option is to include <a href="http://php.net/manual/en/language.constants.predefined.php">‘magic constants’</a> like __FILE__ and __LINE__ in your log output.</p><pre>&lt;?php</pre><pre>function fetch_data_from_file(string $file_path) : iterable {<br>    error_log(sprintf(&quot;A: %d bytes used\n&quot;, memory_get_usage()));<br>    /** original code... **/<br>    error_log(sprintf(&quot;B: %d bytes used\n&quot;, memory_get_usage());<br>    return $lines;<br>}</pre><pre>function finding_nemo(string $filepath) : int {<br>    error_log(sprintf(&quot;C: %d bytes used\n&quot;, memory_get_usage()));<br>    /** original code... **/<br>    error_log(sprintf(&quot;D: %d bytes used\n&quot;, memory_get_usage()));<br>    return -1; //nemo not found<br>}</pre><pre>finding_nemo(&quot;the_sea.txt&quot;);</pre><p>When we run our example now, we have the following log output:</p><p>C: 406912 bytes used<br>A: 406912 bytes used<br>B: 3599952 bytes used<br>D: 3591384 bytes used</p><p>That’s interesting: until marker A, there is no problem. Between line A and B, the memory suddenly starts to increase. These markers correspond to the start and end of the fetch_data_from_file function. Let&#39;s try to confirm this hypothesis using another technique.</p><h3>Xdebug profiler</h3><p>As a PHP programmer, you probably have heard of (and used) Xdebug. If you haven’t, check it out and make sure to install it. What you might not know, is that it also comes with a <a href="https://en.wikipedia.org/wiki/Profiling_(computer_programming)">profiler</a>: a tool which provides insight in the run time behaviour of a program. This profiler is much more sophisticated than the PHP functions mentioned earlier: instead of giving you just information about how much memory is used, it also provides insight in which functions are actually allocating memory. This is an advantage over the previous technique, because if you don’t really have a clue where to look for your memory problem, you will have to scatter a huge amount of calls to memory_get_usage all over your codebase. Before being able to use the profiler, there are some things that need to be configured in your php.ini. Note that most of these options cannot be set at run time using ini_set. <br>First, you have to enable the profiler. This can be done in two ways: either by using xdebug.profiler_enable = 1 or by using xdebug.profiler_trigger_enable = 1. When using the first option, a profile is generated for <em>every</em> run of your program. The second option only creates a profile of your running program if there is a GET/POST variable or COOKIE set with the name XDEBUG_PROFILER. You also have to tell Xdebug where it has to store the generated files, using xdebug.profiler_output_dir. <br>There are <a href="https://xdebug.org/docs/profiler">more things</a> to configure, but with these settings you are already good to go.</p><p>Now, run the script again with the Xdebug profiler enabled. If we look into our configurated output directory, we can find the generated profile there. However, before we can open it, we need another tool: <a href="https://sourceforge.net/projects/qcachegrindwin/">qCachegrind</a> for Windows or <a href="https://kcachegrind.github.io/html/Home.html">kCachegrind</a> for Linux. I will use qCachegrind for now.</p><p>When opening the profile with qCachegrind you will see something like the picture below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ET-Nyq0PqVE0Has8.png" /></figure><p>Make sure you select ‘Memory’ in the dropdown menu at the top of the window, as opposed to ‘Time’ (this option can be useful if performance is an issue).<br>When looking at the ‘callee map’ of the {main} entry in the function list, you can see by the size of the blocks how the called functions have allocated memory. The larger blocks are the most interesting: these are the functions that allocate the most memory. Each called function is located inside the caller in the callee map.In the &#39;Flat Profile&#39; section on the left, you can see a list of functions. For each function, there is an &#39;Incl.&#39; and a &#39;Self&#39; column. &#39;Incl&#39; indicates the amount of memory allocated by this function, including all the memory which is allocated by the callees of that function. &#39;Self&#39; shows the memory which is allocated by the function itself.The functions that are most interesting to look at, are those functions that have a relatively high value in the &#39;Self&#39; column.</p><p>As we can see, there are two functions which take up a lot of memory itself: php:fgets and php:trim. But wait... trim() only trims one line at a time, and fgets only reads one line at a time, right? Why are these functions using so much memory? Here we get at one of the drawbacks of the Xdebug profiler: it generates a &#39;cumulative memory profile&#39;, i.e. when a function is called multiple times, it shows the sum of all the memory that was used over the different times it was called.</p><p>Although the Xdebug profile has its drawbacks, it enables us to see where (potentially) a lot of memory is allocated. We can confirm our hypothesis, namely that the fetch_data_from_file seems to have a problem, as this function calls two PHP functions which allocate a lot of memory.</p><h3>Fixing the script</h3><p>Note that a profiler, or logging memory usage, will almost never give you an exact answer of what or where your memory problem is located. Manual analysis will always be part of your debugging process. However, the tools <em>do</em> help you to build an idea of where the problem might be. At this point, we know which function likely has a problem. Upon closer analysis of the fetch_data_from_file function, we can see that it uses an array to buffer the complete file. If the file is large, the program will run out of memory. Now we do have enough information to fix it.<br>Let&#39;s work with the assumption that fetch_data_from_file is also used elsewhere, and that its behaviour should not change. Luckily, there is a solution for this problem: we do not actually have to load the complete file.</p><p>A relatively simple way to work around this problem is to use a <a href="http://php.net/manual/en/language.generators.overview.php">Generator</a>. This <a href="https://blog.ircmaxell.com/2012/07/what-generators-can-do-for-you.html">excellent post</a> describes the concept in more detail.</p><p>In short, a Generator enables you to write a basic iterator, where you have the control over what information is needed in memory. When looping over an iterator, the loop is in control of when it fetches the next item from the iterator. As the iterator knows how to fetch the next item, it does not neccesarily need to have all items in memory. In this example, this means that there will only be one line of the file in memory at a time.</p><p>Lets look at the example code from above, with a Generator:</p><pre>&lt;?php <br>function fetch_data_from_file(string $file_path) : iterable {<br>    $resource = fopen($file_path, &#39;r&#39;);<br>    while (($line = fgets($resource)) !== false) {<br>        yield trim($line);<br>    }<br>}</pre><pre>function finding_nemo(string $filepath) : int {<br>    $lines = fetch_data_from_file($filepath);<br>    foreach ($lines as $line_number =&gt; $line) {<br>        if ($line === &quot;nemo&quot;) {<br>            return $line_number;<br>        }<br>    }<br>    return -1; //nemo not found<br>}</pre><p>Interestingly, the finding_nemo function did not have to change: foreach loops have no problem with Generators. The fetch_data_from_file function did change: it now contains the yield statement.</p><p>When we log the memory usage for this piece of code, we can see that the usage stays low. However, because Xdebug generates a cumulative memory profile, the Xdebug profile will look more or less the same. This happens because in total, the fetch_data_from_file function indeed allocates the same amount of memory. However, the function now frees its allocated memory sooner, leading to a memory usage that is overall much lower than in the previous version. This is one of the drawbacks of using the Xdebug profiler. In a follow-up post, I&#39;ll show how to use <a href="https://github.com/arnaud-lb/php-memory-profiler/">php-memory-profiler</a>, which generates another type of memory profiles.</p><h3>Conclusion</h3><p>In this post, we saw two methods of locating places in your PHP program where a lot of memory is allocated: first, by using PHP’s memory_get_usage function, thereafter by generating a memory profile using Xdebug and analyzing it with qCachegrind. One thing to keep in mind is that there is no tool or technique available which will indefinetely point to the problem. As such, your debugging process will always at least partly consist of manual analysis. In the next post, I&#39;ll show how <a href="https://github.com/arnaud-lb/php-memory-profiler/">php-memory-profiler</a> can help you to find memory leaks in your program.</p><p><em>Originally published at </em><a href="https://www.moxio.com/blog/33/finding-memory-issues-in-php-programs"><em>www.moxio.com</em></a><em> on October 10, 2018.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5lOvWZnzFwgNgOnH84TRqA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93cd9a4a9049" width="1" height="1" alt=""><hr><p><a href="https://medium.com/moxio/finding-memory-issues-in-php-programs-93cd9a4a9049">Finding memory issues in PHP programs</a> was originally published in <a href="https://medium.com/moxio">Moxio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Start testing with PHPT tests in PHPUnit]]></title>
            <link>https://medium.com/moxio/start-testing-with-phpt-tests-in-phpunit-8614ec94fb95?source=rss----3bdb0f300dbf---4</link>
            <guid isPermaLink="false">https://medium.com/p/8614ec94fb95</guid>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[quality-assurance]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Arnout Boks]]></dc:creator>
            <pubDate>Thu, 21 Jun 2018 10:05:04 GMT</pubDate>
            <atom:updated>2018-06-21T10:04:52.252Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iS8FzNVOGiiUMiShioqgpA.jpeg" /></figure><p>Over the years, automated testing has become an established practice in software development. It thus has also become an essential skill to learn for any developer. In the past few months, I have talked to several developers who had recently started with testing in PHP. Some of them expressed they found their testing framework of choice (often <a href="https://phpunit.de/">PHPUnit</a>) quite difficult to get started with.</p><p>In a sense, this is not surprising. Getting started with testing is already challenging on its own. You have to choose units to test and learn to write testable code. You must learn to distinguish essential behavior from implementation details. At the same time you have to get to know your testing framework. Most popular and mature testing tools need quite some boilerplate and background knowledge. This adds to the already steep learning curve. As people learn best by tackling one step at a time, this is not ideal. It would be much better if we had an easy testing framework that juniors can use to learn the basics of testing without the extra overhead.</p><h3>PHPT tests</h3><p>Enter PHPT tests. Through work on some small bug fixes in the PHP core (and <a href="https://speakerdeck.com/aboks/getting-started-with-php-core-development-php-serbia-2018">speaking about that</a>) I learned about the PHPT test format. This is the test format used for testing the PHP interpreter itself. It is straightforward and simple to get into. The main idea is that a test contains a PHP script that prints output, and the output expected from that script. An elementary PHPT test would look something like this:</p><pre>--TEST--<br>Basic arithmetic - addition<br>--FILE--<br>&lt;?php var_dump(42 + 1); ?&gt;<br>--EXPECT--<br>int(43)</pre><p>Here, the --TEST-- section provides a short description about what the test aims to test. The --FILE-- section contains a script that prints some output. In this case we output the result of adding two integers. After --EXPECT-- comes the output we expect from the --FILE-- section.</p><p>Note that we use var_dump for outputting the result value. If we would use echo or print the output would be just 43. In that case we would not know whether that was the integer 43 or the string “43”. That makes us unable to verify that the result is of the correct type. Therefore we prefer var_dump: it shows the type of the value.</p><p>The PHPT test format is not feature-rich. Still it supports all the constructs necessary to write sensible tests. You can use them by adding these sections:</p><ul><li>--EXPECTF--, --EXPECTREGEX--: Instead of specifying the exact desired output with --EXPECT--, one can specify a pattern for the expected output. This pattern can be provided either as a printf-like string or a regular expression.</li><li>--SKIP--: You can add this section to describe when a test should be skipped. This can be used to check for a specific platform or the presence of a required PHP extension.</li><li>--CLEAN--: When the test creates some temporary artifacts (like files on disk) the code in this section can clean them up.</li><li>--INI--, --ENV--: Sometimes a test needs to run with specific settings like php.ini directives or environment variables. You can specify those settings in these two blocks.</li></ul><p>More information about the PHPT test structure can be found on the <a href="https://qa.php.net/phpt_details.php">website of the PHP QA team</a>.</p><h3>Learning to test with PHPT</h3><p>When learning to test, we can see the frugal feature set of PHPT as an advantage. It allows one to focus on learning the concepts of testing and testability without getting lost in features of a specific testing framework. These features are useful for developers that are already accustomed to testing. Still it is better to build understanding of how they work under the hood first. In fact, juniors will probably find a way to emulate them in a ‘naive’ way using concepts they already know:</p><ul><li>Want to test that a function throws an exception? Use a try-catch. No need for expectException() yet.</li><li>Have multiple tests that look similar, but with different data? Put them in a for- or foreach-loop. This paves the way for a data provider later on.</li><li>Sharing some initialization logic between tests? Move it to a function. Later on such a function can become a setUp-method.</li><li>Need a test double? Create a dummy implementation within the test yourself. This helps to learn what a mocking library does under the hood. It also encourages to keep interfaces small and method chains short. Patterns for the different types of test doubles will emerge more naturally. We don’t have them all coming from createMock() anymore. This helps juniors to learn how e.g. a stub differs from a mock.</li></ul><p>As a bonus, PHPT tests make it easy to write <a href="https://michaelfeathers.silvrback.com/characterization-testing">characterisation tests</a>. Take any code fragment that exercises the system under test in some way and put it in the test. Then run it to get the current output and register that as the expected output. This strategy provides a great opportunity to learn how one can use characterisation tests as an aid to refactor legacy code. It also teaches how they are brittle and should eventually be replaced by tests that properly specify desired behavior.</p><h3>Using PHPT tests with PHPUnit</h3><p>One little-known feature of PHPUnit is that it actually has built-in support for PHPT tests out of the box. All we have to do to enable this is to add a directory with the .phpt suffix to the phpunit.xml configuration file:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;phpunit bootstrap=&quot;vendor/autoload.php&quot;&gt;<br>    &lt;testsuites&gt;<br>        &lt;testsuite name=&quot;My Test Suite&quot;&gt;<br>           &lt;directory&gt;test&lt;/directory&gt;<br>           &lt;!-- (line below added) --&gt;<br>           &lt;directory suffix=&quot;.phpt&quot;&gt;test&lt;/directory&gt;<br>        &lt;/testsuite&gt;<br>    &lt;/testsuites&gt;<br>    &lt;!-- ... --&gt;<br>&lt;/phpunit&gt;</pre><p>If we have done so, PHPUnit will also look for .phpt files in the test directory, and execute them as PHPT tests. With this configuration we can start mixing ‘normal’ PHPUnit tests and PHPT tests. Still we can run them as if there were no difference. We just support both test formats side-by-side without any extra infrastructure or tooling.</p><p>This means developers experienced with testing can still write their usual PHPUnit tests. Developers that have recently started out with testing now have a simpler way of writing tests though. Instead of the following test from the <a href="https://phpunit.readthedocs.io/en/7.1/writing-tests-for-phpunit.html">PHPUnit manual</a></p><pre>&lt;?php<br>use PHPUnit\Framework\TestCase;</pre><pre>class StackTest extends TestCase {<br>    public function testPushAndPop() {<br>        $stack = [];<br>        $this-&gt;assertSame(0, count($stack));</pre><pre>        array_push($stack, &#39;foo&#39;);<br>        $this-&gt;assertSame(&#39;foo&#39;, $stack[count($stack)-1]);<br>        $this-&gt;assertSame(1, count($stack));</pre><pre>        $this-&gt;assertSame(&#39;foo&#39;, array_pop($stack));<br>        $this-&gt;assertSame(0, count($stack));<br>    }<br>}</pre><p>you can write this equivalent PHPT test:</p><pre>--TEST--<br>Array as a stack<br>--FILE--<br>&lt;?php<br>$stack = [];<br>var_dump(count($stack));</pre><pre>array_push($stack, &#39;foo&#39;);<br>var_dump($stack[count($stack)-1]);<br>var_dump(count($stack));</pre><pre>var_dump(array_pop($stack));<br>var_dump(count($stack)); <br>?&gt;<br>--EXPECT--<br>int(0)<br>string(3) &quot;foo&quot;<br>int(1)<br>string(3) &quot;foo&quot;<br>int(0)</pre><p>Notice the differences in boilerplate/prerequisites to understand the two tests. For the PHPUnit test one needs to know about the PHPUnit TestCase class and have a basic understanding of OOP. Also you have to know that methods starting with test are invoked by the PHPUnit test runner. Lastly, you need to be able to pick the appropriate assertion method.<br> With the PHPT test juniors can take any existing snippet of PHP code that produces some output and turn it into an automated test. They might already use such a script for manual testing. Now they can convert it to a test that runs with the rest of the testsuite.</p><h3>Limitations</h3><p>Of course, most of us do not write tests using PHPT, but use a framework like PHPUnit, <a href="https://www.phpspec.net/">phpspec</a> or <a href="http://atoum.org/">atoum</a>. There are good reasons for that. Using the PHPT format and running it with PHPUnit has some serious limitations:</p><ul><li>Features. Most test frameworks have several helpful features built-in. These help to reduce the amount of code to write for certain tests or clarify why certain tests failed. Think of data providers and integration with mocking libraries. But there are also test dependencies, ways of expecting exceptions and specialized assertion methods. We have discussed that most of these can be ‘emulated’ in tests themselves. Still, having these in our test framework reduces the amount of boilerplate we need to write. It makes experienced testers much more productive.</li><li>IDE support. There is no real support for PHPT tests in most IDE’s. With proper file associations the code between &lt;?php ?&gt; tags is usually still highlighted. The PHPT sections will not be, though. Additionally, I don’t know of any IDE that can quickly run a single .phpt file as a PHPT test from the editor.</li><li>Unsupported sections. The PHPUnit test runner has only limited support for PHPT tests. <a href="https://github.com/sebastianbergmann/phpunit/blob/f77161e67093f1bb8778ee5522e8c5e9ee0f4384/src/Runner/PhptTestCase.php#L338">Several PHPT sections</a> are not supported by this runner, most of them related to simulating HTTP input.</li></ul><h3>Conclusion</h3><p>I see no use in switching to PHPT tests if you are already experienced in writing tests. Still, using PHPT tests might be a nice way for less experienced developers to get started with testing. With little boilerplate and a small feature set, it helps them to focus on ways of testing and writing testable code. That is difficult enough in itself, and deserves their full attention. More advanced features and constructs will arise naturally and help to discover how a testing framework works under the hood.</p><p>Most important: in PHPUnit, PHPT tests can be enabled alongside ‘normal’ tests with just a single line of configuration. Such a strategy provides a smooth upgrade path from basic PHPT tests to a more mature testing framework. It does not even require additional tooling. Help your developers to start testing, enable PHPT tests!</p><p><em>Originally published at </em><a href="https://www.moxio.com/blog/32/start-testing-with-phpt-tests-in-phpunit"><em>www.moxio.com</em></a><em> on June 21, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8614ec94fb95" width="1" height="1" alt=""><hr><p><a href="https://medium.com/moxio/start-testing-with-phpt-tests-in-phpunit-8614ec94fb95">Start testing with PHPT tests in PHPUnit</a> was originally published in <a href="https://medium.com/moxio">Moxio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creative Sessions: Getting what we really want]]></title>
            <link>https://medium.com/moxio/creative-sessions-getting-what-we-really-want-8ef57617f3f7?source=rss----3bdb0f300dbf---4</link>
            <guid isPermaLink="false">https://medium.com/p/8ef57617f3f7</guid>
            <category><![CDATA[feedback]]></category>
            <category><![CDATA[user-research]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[creative-session]]></category>
            <dc:creator><![CDATA[Didi Groenhoff]]></dc:creator>
            <pubDate>Thu, 21 Jun 2018 09:29:58 GMT</pubDate>
            <atom:updated>2018-06-21T09:29:58.316Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IZOoIG3h0EYvwe6102krww.jpeg" /></figure><p>When holding a creative session with our users we always make sure to get all brains empty and loosened up first, making sure everyone is in a positive, constructive vibe ready to give us as much quality input as possible. (Read how we go about that <a href="https://www.moxio.com/blog/26/creative-sessions-how-to-get-that-positive-vibe">here</a>) But then we get to the point we want to get down to the nitty gritty. We <a href="https://www.moxio.com/blog/21/creative-sessions-the-set-up">prepared</a> a research goal, and we want answers. In this blog we share how we get them. We offer our users a set of exercises, and keep our ears and eyes open while they work on them.</p><h3>Exercises</h3><p>First we ask our users to describe their entire work process, specifically on the research goal set for that day. With ‘entire’ we mean we’re not only interested in what they do <em>in</em> our application, and if that works for them, but also what they do <em>outside</em> of our application, how, and why. This way we get a complete view of all work flows. To complete this task we offer very simple means: paper, markers and optionally stickers to point out where the process fits the application very well, or where the process gets stuck.</p><p>Often we want our group to focus on a specific part of their work process. To focus on that we tend to do another small exercise pointing them in the right direction, or give them a questionnaire bringing certain subjects to the front of their brain as a conversation starter.</p><p>Every exercise leads to a discussion between users. Listening in is the best input for us. The more diversity we have in our group, the better view we get on the complete work process, linking workflows of users that follow each other up in the real world. This also leads to users talking to each other while penning down their work process, which helps users detach from their own world, have an objective look, compare their process to others, and see overlap and confrontations in other people’s needs. This helps us determine where one solution can fit all, or where different users have such different needs that one size fits all will not meet them. Our users also learn from each other, seeing someone else performing a comparable task in a totally different manner. We are all winners here.</p><p>Last but not least we spend the last 20 minutes on a ‘free exercise’. This is where we let our users go completely bananas, and because of the relaxed atmosphere and interesting conversations they’ve experienced in the earlier exercises, our users usually feel they have the freedom let it all go. One exercise we like is posing a problem, having a small group of people draw up a sensible solution, and the having them draw up something they know will never come in to being, but would be really cool. What this leads to is always a surprise. Some groups come up with sheer nonsense, but other groups come up with sheer nonsense that actually gives us more insight in what they really want our application to do for them. Looking at the shaping of ideas that normally would have never been shared because ‘it’s never going to work’ can be just the input we need to get a better comprehension of the problem, and developing a good solution that does work.</p><h3>What do we do?</h3><p>So during all this writing, drawing and discussing, what is it that <em>we</em>, the UX-designers and information specialists, do aside from giving instructions for the exercises?</p><ul><li>We listen: we listen to what people are saying, and make sure people know we are truly interested and value their input.</li><li>We ask questions: if users come up with working processes or issues we don’t fully understand we keep asking until we do fully grasp what’s going on.</li><li>We write: we make sure to write down what people are saying, so it’s documented and will not be forgotten. Where needed we make pictures. We also make sure to document who came up with what issue or idea, so that we can always ask them for more input once we’ve started working on their problem.</li></ul><p>Simple as this may sound, paying attention to actually doing this well and focused makes that we get much more and better input. Also, this attitude creates trust with our users that we appreciate their opinions, are going to work with their ideas and their time and energy is valuable to us. Offering attention and focus is the basis of a good relationship.</p><h3>Closing the session</h3><p>To once more bring across this message, we put time and effort in closing the session. We thank our users, try to summarize what we’ve picked up that day, and very important: offer them a small present to thank them again. As one participant once said: ‘It’s not the company note book and mug you just gave me. It’s the fact that you took time to wrap it up nicely tie a ribbon around it that shows me you really care.’ That is what we try to do during our whole session, and after.</p><p>Follow up blogs:</p><p><a href="https://www.moxio.com/blog/30/creative-sessions-getting-what-we-really-want">Creative Sessions: Getting what we really want</a></p><p><em>Originally published at </em><a href="https://www.moxio.com/blog/30/creative-sessions-getting-what-we-really-want"><em>www.moxio.com</em></a><em> on April 11, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ef57617f3f7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/moxio/creative-sessions-getting-what-we-really-want-8ef57617f3f7">Creative Sessions: Getting what we really want</a> was originally published in <a href="https://medium.com/moxio">Moxio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>