Pages

Monday, October 23, 2017

Bronze Sword Casting Birthday Present

For my 30th birthday my wife decided to do something special. She happens to be an excellent gift giver, and this time she had outdone herself. With my background in history, and my interest in all things nerdy... My wife had found a local Bronze Sword casting class! Now, I didn't actually know a whole lot about bronze swords - just a general idea that they existed and that they fell by the way due to Iron. That said - the class sounded really exciting! 

The class was over a period of three days. The first day involved packing a sand cast. A sand cast is one inexpensive method for holding molten bronze while it quickly cools. It's also reminiscent of making sand castles. Here you can see the impression left by the mold I chose.
After choosing the mold, the next step was to heat the bronze in a kiln, and poor it into the cast.


After the bronze had cooled, which made time go slowly because of anticipation, the sword was removed from the cast. As you can see, some of the sand stuck to the bronze, and, the bronze itself was quite rough.


On the second day, a considerable amount of time was spent sanding down the sword. It was quite a noisy endeavor! The first pass was a rough sandpaper. It made the metal gleam, but, was still quite rough. After we stepped through the levels of finer sandpaper, the sword was really starting to take shape.






The final day, we put the handle on the sword. This involved a hammered rivets. The handle we added reminded me very much of Chicago Cutlery.  


Many Hammer strikes later, and after a little bit of polishing of the handle, the sword was complete.

Bonus: After the class was over, I headed over to Hobby Lobby and picked up some leather. I used this to put together a sheath. Here is the final product. All in all, it was a great birthday present from my wife. :)


Saturday, October 21, 2017

Guide: Implementing a PhpUnit Development Environment in PhpStorm

Introduction

Unit testing is one of the most critical aspects of Continuous Integration. For some background, I like the idea of TDD, but in the end… I am a developer, I code first, ask questions later. A sample repository can be found on GitHub

Preparation

For this example, I will be starting with the following:
  • PhpTraits repository https://github.com/Waryway/PhpTraits
  • PhpStorm Project
    • Make certain you have a php interpreter referenced in your storm project
    • Also make certain you have Composer referenced by PHPStorm
  • A desire to test.allTheThings()



Getting started

Let's start from the very beginning

First, make composer do some work. We need a copy of phpunit.
Get it with this:
"require-dev":{ 
    "phpunit/phpunit":"6.4.3" 
}

As this is a 'library' style app - use an exact version. The lock file gets ignored in favor of precise dependencies in the composer.json.

Now run composer update to pull in the requested phpunit package.

Setup phpunit in the general settings, under phpunit


Adding a new test

Or rather, a test skeleton

  1. Open the file to test in the Project View
  2. Place you cursor on a method to test within the file
  3. Go To Navigate -> Test
  4. Create New test
  5. I tend to set mine up with a test prefix to keep tests more obviously separate from code.
  1. Click Ok then Open up the new file
  2. Add a line to pull in the composer autoloader
  3. Clean up the Namespace reference to the TestCase if you are using PSR-4
  4. Disclaimer: Strongly avoid namespacing unit tests. They should not be built out like a code base. They are testing units.
  5. Add an empty testHydrate method.
  6. Add a super obvious assertion.
  7. Add a phpunit.xml file
    1. I put it in the test directory.
  8. Run the test (At this point, I needed to restart phpstorm to detect that I actually had a 'test' to run.
  9. Build the tests out further.

Conclusion

Ending of the beginning

I've gone ahead and built out the 'hydrate' test against a trait. Note the use of the trait object that phpunit provides. Pretty slick, right?  I'll continue to build out this repository - core libraries need the most directed test coverage.


Even adding the 'test' cases around the hydrate method - I have found use cases I didn't consider while writing the code - and have adjusted the code to reflect the behavior I expect.

You can find this repository on GitHub! This post might need some more work, feel free to ask questions or for updated instructions.  Thanks!