Wednesday, December 23, 2020

Laugh/Cry Emojii


Originally, this post was going to be a quick celebratory splat that I had actually managed to create a functional API endpoint in Mabel now that the php-common library is more updated.

Then I google stumbled across Slim 4.

Not sure how this slipped past me but Slim 3 apparently underwent a major version upgrade to Slim 4 in August 2019.

Luckily, I haven't written much actual code yet so I won't need to re-work all that much.

Monday, December 21, 2020

Phew. Are These Unit Test Updates Ever Going To End?

 Rhetorical question, that was.

The php-common library has largely (not going to update the code for AMQP or Syfmony Console until I know for sure I need to use it) been updated with PHP 7.4 bells and whistles.

The unit tests are updated as well and they're all passing except for the handful that are skipped.

I'm not going to do much more to update the unit test code until I'm ready to tackle the upgrade to PHPUnit 9 (or 10 depending on when I do the upgrade) until I get some other things done first.

So, starting tomorrow I'll be diving back into working on mabel . . . itself . . . herself?

Friday, December 18, 2020

Urgh Unit Tests

I'm not going to lie. Writing and/or updating unit tests can be incredibly tedious. It's a chore I don't love, but it's a chore that must be done.

The updates I referenced in my prior post have taken on that aspect where you feel like you're unweaving a bunch of code so that you can weave it back together again in a better form. It's a little scary at first because you find yourself wondering "Can I put this mess back together in a reasonable amount of time?"

Basically, the refactor I did to remove the "passthrough" connection class meant that I had to change the constructor of the fairly heavily used "AbstractActiveRecord" class if I wanted the code to continue to enforce the concept of dependency injection. That change has rippled throughout the code and resulted in a lot of unit tests needing to be updated.

And honestly? This is EXACTLY WHY YOU WRITE UNIT TESTS. So that when you make changes to your code in one place you know exactly where those changes require subsequent updates to other code. I just wish it weren't so . . . messy.


Wednesday, December 16, 2020

When Good Ideas Turn Bad

 In retrospect, maybe it wasn't such a good idea.

I've used doctrine/dbal for years now. I like having a 3rd party library that I can use to interact with a database but I don't want all the complexity and overhead of a full fledged ORM. Besides, I just don't like ORM's all that much. I 'feel' that they lead to coding practices that result in 'bad' SQL.

Anyhow, shortly after we started using DBAL, my dev team at the time also saw the way, the truth and the light when it came to dependency injection. One of the concerns we had at the time though was how to be sure that we were only testing our code and not unintentionally testing the code of any 3rd party libraries that we were using.

For DBAL, our (my since I'm the idjit that did it) solution to this conundrum was to wrap the connection class in our own connection class that acted as a big passthrough. That way, when we were mocking the connection class for a unit test, we were mocking OUR class and not THEIR class.

In retrospect (and now that I'm a lot more comfortable with DI) I'm not really sure why this seemed like a good idea. I suppose it didn't really harm anything, but it really didn't help either. Is there really any difference between mocking a class that lives in our code that's basically just a big passthrough and mocking the code that's being pass through too?

And it turns out that there's one gigantic flaw that won't appear until there's a major version update that fundamentally changes the API of the source class the passthrough is based on. When that happens, your unit tests will continue to pass even though they REALLY REALLY REALLY should not.

So yeah, I am going to have to revisit the approach that the common library I'm using has with respect to DBAL. I am most likely going to do away with the passthrough class entirely as I'm just not seeing all that much difference between mocking a passthrough class and the base class itself. The passthrough has a couple of modifications that enforced team specific practices at the time, so I'll need to revisit those as well and decided if/how they should be preserved.

In My Head Vs. In Reality

In my head, Slim 3 is super shiny and new. In reality, it's been around since at least 2015.  I find this ironic and I wonder if there's something more modern out there.

Anyhow, it seems to be working well enough. I had a bit of trouble figuring out how to setup the routing correctly so that I could define my controller actions as methods inside classes, but ultimately I found a helpful blog post that put me on the right path. Same goes for correctly using the dependency injection container.

Sunday, December 13, 2020

Slim 3 Is the Way

 So yeah, I'm going to switch to Slim 3. My 100% scientific reasons? 

  1. It seems to be structured very similarly to Silex.
  2. It's compatible with the version of PHP I'm currently using (PHP 7.4.11).
  3. It appears to be quite lightweight (no benchmarks or whatnot to prove that as of yet).
  4. I can install it via composer without any of the problems I was experiencing with Symfony/Flex
  5. It is (according to Laravel) faster than Silex.
  6. It uses Pimple as a dependency injection container and I loves me some DI.




Other Routing Options

In reference to the post from December 10th, I've come to the following conclusions.

  1. I should look into Docker as a replacement for VirtualBox. I've been planning to look into Docker for some time now and I guess I have an even better reason for that now.
  2. I'm going to look into a replacement for Silex that is not a component of a larger (and heavier) framework like Symfony or Laravel. I just need straightforward, fast and reliable routing and I don't want (or need) a lot of other bells and whistles.

In that vein, I am looking at Slim 3 as a replacement for Silex.

Thursday, December 10, 2020

A Routing Conundrum


I started to actually work on the authorization service (which I have decided to name Mabel) and quickly discovered to my shock and horror that silex/silex has been abandoned. Basically, this is the routing framework that I'm used to using and I wasn't expecting to have to change.

The suggested replacement is symfony/flex. To be honest I'm not exactly sure what symfony/flex even is. It guess it's some sort of code generator that allows you to create the skeleton of a Symfony project by executing a series of commands from the command line. I guess it also handles setting up the routing to your controllers the same way. I'm probably not doing it any justice in my 'description' but that was my takeaway from the documentation/marketing materials on the Symfony site.

It's a personal failing of mine that I'm too resistant to change. I'm deeply skeptical of any new technology until I get to a point where I feel like I understand whatever it's trying to be or do. Knowing that, I set my discomfort aside and decided to keep an open mind and try out this symfony/flex thing as potentially the new way forward.

Only I can't. I can't really install it. There's some sort of weird conflict happening because I'm attempting to use a combination of VirtualBox 6.1, Vagrant, PHP 7.4 and Symfony 5.

I'm not really sure what to do. Should I:

  1. Switch to a different virtualization technology since this problem appears to be specific to VirtualBox?
  2. Continue to use silex/silex even though it's been abandoned?
  3. Find documentation that explains how to manually construct the routing in Symfony 5?
  4. Find some other lightweight routing framework to use that I can install via composer?
  5. Kludge together my own lightweight routing framework (possibly using candidates from 4 and silex/silex as an example)?
I'm really not sure which option to select. They all have their pros and cons.

Why We Write Unit Tests

When I left off in early November, I had largely gotten my development environment up and running. That meant it was time to start delving back into the code. The first thing I'm going to write for Robot Fortress is an authorization and user data service. After all, this is going to be an online multiplayer game and to do that I'm going to need to expose a bunch of service endpoints to the brutal chaos that is the modern internet.

I've got quite a lot of experience writing these kinds of services using a Linux/Nginx/MySQL/PHP stack, so it's also a nice place to start and get my head properly back into 'coding space.' Writing the client in Unity is going to be the real stretch (though I do know C#) so I want to start with something more familiar.

As it happens, I have a php library that contains a number of useful classes that will make writing this service a bit easier. However, it is out of date in the following ways:

  • The library was last updated to be compatible with 7.1 but the current installed version of PHP on my local environment is PHP 7.4.11 
  • There have been two additional patch updates to PHP 7.4.13 but Amazon Extras doesn't appear to have those yet so I can't upgrade my dev environment or my production server.
  • At last update, the library's unit tests were written again PHP Unit 7.3.5 but PHPUnit is currently on version 9. As it stands, the version of PHPUnit installed on my local machine is 7.5.20.
  • All of the composer packages that the library is built on top of were up to date for PHP 7.1, which means they're all out of date as well.

So here's what I did:

  • Ran the unit tests and saw what failed (quite a lot) either because of the update of php from 7.1 to 7.4.11 or the update of PHPUnit from 7.3.5 to 7.5.20.
  • Updated the unit tests and the code until everything passed.
  • Individually updated each of the composer package.
  • After each composer package update, re-run the unit tests, noting what failed and then fixing either the code or the test as appropriate.

In the end, 854 tests are passing and 3 are currently skipped. The 3 that are skipped are from tests that appear to be failing due to changes in how objects are mocked in PHPUnit. Since I'm going to have update the entire library to be compatible with a 2 major version upgrade to PHPUnit, I decided to defer fixing those tests until that time comes.

I can't even imagine how difficult this would have been if the library had not come in with a high level of unit test coverage.

THIS IS WHY WE UNIT TEST.

THIS IS WHY WE USE DEPENDENCY INJECTION.


Picking This Back Up

Like it's some sort of heavy weight and I have to remember to bend from the knees, not the back.

But seriously, sometimes life just happens and things fall by the wayside.

Anyhow, for all of you who are avidly following this blog (Hah hah hah. Maybe I should start tweeting?) I'm starting to work on Robot Fortress again.