r/ruby•
-blind

Build tests in Ruby for PHP code?

Context: Took a job for a Rails dev position. There was the stipulation I would transition to the dev team after learning the system from the QA side. Well, the QA side turns out to be their legacy PHP application... and I haven't touched PHP since I graduated. Couple people left and now I'm basically running the QA boat unfortunately - so my stay might be more extended than I'd like. Every bug fix / feature is QA'd manually - and that has to change.

About the system in place:

  • Current test "suite" is Cucumber + a Selenium driver : low coverage, basically an automated user running through different use paths. Tests fail intermittently. This happens with timeouts due to bloated PHP code, slow unpredictable AJAX UI changes necessary to navigate pages, chromedriver losing focus on javascript alert boxes.
  • Every cucumber feature is preceded and predicated with a login / logout because there are different user access contexts (admin / staff / member / etc.), and that's the only way to encapsulate the tests. So a single run of the test "suite" will check against 118ish scenarios... and authenticate about 600ish times. Horribly inefficient.
  • The "senior" dev's on the ruby team, for whatever reason, don't build rspec tests on their features. So I'm hoping I can transition whatever way I test out this application to the ruby system as well... because I foresee getting stuck with that QA as well.

I'm trying to test below the user level - unit test on PHP classes / files / behaviors directly. I DON'T want to relearn php just to build out these tests so can I go about this with Ruby in some way? Anyone have some ideas?

TLDR ; Is there a tool / approach to unit test PHP code with Ruby?

Posted May 23, 2015, 5:49 PM UTC

512
jmking•

There's no way to unit test code in PHP with Ruby.

Just suck it up and refresh your PHP. Modern PHP really isn't that bad.

...and if these Ruby devs are the same people who build this slow, bloated PHP mess, then they're also writing slow, bloated messes in Ruby too. Sounds like you got bait and switched anyway.

6
tdammers•

Modern PHP really isn't that bad.

Yes it is.

5
-blindOP•

A majority of the PHP application was outsourced to overseas contractors and we all know what a bitch it is to refactor legacy php code, so I hope that's not the case with the ruby code base (if it is I'm on my way out lol)

Thanks for responding - I was hoping that was not the case, I don't really want to give them a reason to keep me around the PHP team longer than necessary.

I don't know if "bait and switch" is a common thing in the industry or how other companies go about it, it's my first full-time gig, but this just seems the process they bring new dev's along on here. I definitely feel slightly cheated and misled - but I couldn't have predicted the other team members around me leaving abruptly like this

2
Godd2•

There's no way to unit test code in PHP with Ruby.

Surely you can make system calls and get responses back. Or spin up a server and make requests.

Can you elaborate on what you mean by "There's no way"? Or is there some semantics involved here on "unit test"?

0
jmking•

Unit tests are, essentially, testing individuals functions in code. This usually means invoking function calls, passing in mocked objects, and asserting expected output.

You can't invoke PHP functions and pass in PHP objects to those functions from Ruby.

2
bonquesha99•

I don't know of any existing tools like that but this sounds like it could be a pretty fun and interesting project!

You can try building a tool on top of u/tenderlove's library, phuby, which exposes a PHP runtime within Ruby.

Let me know if you end up making any progress on a tool like this! I've been experimenting with building the PHP side of phuby which is a port of Ruby's object model system and standard library.

I love seeing projects that "bridge" languages together. Both Ruby and PHP are awesome languages that are incredibly fun to work with!

5
kobaltzz•

Why is the company worried about unit testing on a legacy application? It sounds like this application is in maintenance mode and as such, additional tests to cover existing functionality would be rather futile. What is the EoL of the legacy application?

2
-blindOP•

The company isn't. I am. Because while they are sunsetting the app - it is still the prime money maker. They've customized it on a per client basis. I agree it's beyond futile and my skill would be better spent doing dev work, I am not in that position however and stuck doing QA - and I'd rather automate tests than manually do it each time some shit gets hack patched.

1
tf2ftw•

Honestly if it were me I'd be looking for a new job. Unless you want to become a PHP dev let someone else do it and find a much better (fun) Ruby job.

1
-blindOP•

I agree - and don't want / plan on letting that happen. Hence the desire to avoid php. The Ruby team is building a quality snd interesting product with good people on it and I'd like to be a part of that so I want to see it out and was weighing options

1
Enumerable_any•

I don't think there is a way to do this [1]. If you already know Ruby, learning PHP should be pretty easy.

[1] You could write a PHP -> Ruby compiler and test against the generated Ruby code. /s

-1
tomthecool•

You could write a PHP -> Ruby compiler

Sounds trivial! This is clearly the best option ;)

1