Tag Info

Hot answers tagged

76

Regression testing It's all about regression testing. Imagine the next developer looking at your method and noticing that you are using magical numbers. He was told that magical numbers are evil, so he creates two constants, one for the number two, the other one for the number three—there is nothing wrong in doing this change; it's not like he was ...


43

Because nothing is so simple that there can't be bugs. Your code, while on the face of it looks to be bug free. It is in fact a simple programmatic representation of a polynomial function. Except it has a bug... public function polynominal($a, $b, $c, $d) { return $a * pow($x, 3) + $b * pow($x, 2) + $c * $x + $d; } $x is not defined as an input to ...


20

Yes. If we could say with 100% confidence, with certainty: this function will never be edited and will never run in a context which could cause it to fail - if we could say that, we could drop the tests and save a few milliseconds on every CI build. But we can't. Or, we can't with many functions. And it's simpler to have a rule of running all the tests ...


12

Everything said in the other answers is correct, but I will add one more. Documentation Unit tests, if well written, can explain to a developer exactly what a function does, what its input/output expectations are, and more importantly, what behavior can be expected of it. It can make spotting a bug easier and lower confusion. Not everybody remembers ...


11

The problem you are addressing is quite fundamental. I have experienced the same problem when I worked for a company that made a large J2EE application that consisted of several hundred web pages and over a million and a half lines of Java code. This code used ORM (JPA) for persistence. This problem get worse when you use 3rd party technologies in every ...


8

Attempt to fetch the user record based on the username (but use LIKE instead of = so that case doesn't matter. Usernames should not be case sensitive. If you managed to fetch a user record (then the user exists) and you can compare the passwords to validate the login. About password security Store the passwords using a function like password_hash() so ...


7

The problem you facing is an old one: code for persistent objects often looks similar for each class, it is simply boilerplate code. That's why some smart people invented Object Relational Mappers - they solve exactly that problem. See this former SO post for a list of ORMs for PHP. When existing ORMs do not suffer your needs, there is also an alternative: ...


7

Is there a technique for unit testing both components in one run? That would actually be the opposite of unit testing - unit testing, especially in TDD style, means to test your components in isolation. Thus the answer is yes, "run separate test suites for the JS and PHP sections", otherwise it is not unit testing and not TDD. Of course, automated ...


5

I would agree that this is not a good idea. Even if the language you're using defines what should happen in this situation (I don't know if PHP does; that's a question for StackOverflow) most people who see code like this would still have to look up whether or not it's defined behavior before they could have any confidence in it. If the list of desired ...


4

Okay, first things first: you're running PHP 5.2!? There's not really much reason to stay with that other than having out of date servers, and that means it's either time to switch hosts or update your servers because PHP 5.2 has some major known security holes which aren't ever going to be fixed. This'll also give you access to a bunch of new features, the ...


4

The service shouldn't make any decisions or you end up with a anemic domain model. Your license aggregate should make the decisions. If the license aggregate needs to call a web service you pass an instance of a helper for that service to the method on the aggregate. It can them choose to use them if it so wishes.


4

After some investigation, I would say this seems pretty optimal. Please see my gist here. In the PHP file in the gist I've generated some nested arrays with unsorted keys using one function, counted the total number of keys (including keys in nested arrays) using the recursive option to count, timed sorting the array using your function above, generated a ...


4

Whenever a database has multiple concurrent writers, there are potential race conditions. In particular, if each writer tries to add a new row, they may all choose the same primary key if they're just doing max(...)+1, and then all but one of the inserts will fail. When a database has an "auto increment" feature, they're not saving you the trouble of ...


3

First of all, I wouldn't approach a clean architecture in PHP. One of the main goals of clean architecture is to allow the user interface to be considered as essentially a plugin to the application, allowing you to change between types of UI easily. By going with PHP you are restricting yourself essentially to web-based interfaces. If you are familiar with a ...


2

The important thing is to distinguish between TDD and ATDD. The AT there stands for "acceptance tests", and this refers to development where you first start with an acceptance test, which is likely to test the entire stack. This is also sometimes called "outside-in test driven development". When people talk about TDD, the "T" there probably refers ...


2

Typically I'd just search the table for the record that contains the matching username. If that record doesn't exist the user doesn't exist so there is no need to go any further. If the record does exist that record would have the password hash on it for that user. Take the password given by the user, hash it in the same way, compare to the hash in your ...


2

Most dependency injection containers can be configured to create the dependencies as well as inject them. No need to have a separate process to create dependencies. Here is a simple example using the PHP Pimple container(http://pimple.sensiolabs.org/) // This is the importer service definition $dic['arbiter_schedule_importer_games_with_slots_xml'] = ...


2

Reality Check I have been in challenging environments where testing is "a waste of time" during budgeting and schedule, and then "a fundamental part of quality assurance" once the customer is dealing with bugs, so my opinion is more fluid than others might be. You have a budget. Your job is to get the best product you can on that budget, for whatever ...


2

Keep your DTO's simple You are right that having a command with 9 arguments in the constructor is ugly. But do you really HAVE to put those things into the constructor? Make your fields public, create your command with an empty constructor and just assign to the fields. The point of constructor arguments is to have guaranteed valid entities, since you are ...


2

The answer to your question, that number you are seeing is called a GUID. Its a number format that can be generated quickly, and is mathematically just short of being guaranteed that neither yourself or anyone else will generate a new guid, with the same value. It is quite likely that this is used as the identifier in the database record for that product. ...


2

In PHP the foreach loop creates a temporary variable storing the initial array passed. you can pass $value by reference using &$value. In the two examples below the loops remove the next element in the array. Since it is a temporary variable changes to the original have no effect on the foreach loop. <?php $arr = array(1,2,3,4,5,6,7,8,9); ...


2

Notice that a complex program does not need to be coded in several languages. For example, the Linux kernel is a complex program (of more than ten millions source lines of C code with a bit of assembly). Then, mixing multiple languages is implementation specific (often related to foreign function interface) but most language implementations offer the ...


2

I've always liked cron. I think it's easy to understand, and (like most *nix apps) it only does one thing - launch scripts when the current date/time matches a pattern. What those scripts do, however, is a completely different story. If they are well written and tested, they can be awesome - critical components of your day-to-day operations. If poorly ...


1

You compile each source file into object files using the appropriate complier for its language, then link the object files into an executable, the same way you would for any other program. For this to work, all the compilers have to agree on how the modules communicate with each other. This includes things such as: what symbol names the objects export and ...


1

I agree with Snowman, but as to not leave you empty handed, I will discuss a few possibilities. If by 'doing the front-end work', you have primarily been tasked with designing the project, then you can design the site according to your normal workflow and simply pass it off to him to integrate it. If you are responsible for everything client-side, then you ...


1

Your best bet for this if your intended clients have sufficiently modern web browsers is Web Sockets. There are plenty of libraries out there that you can use and can look into. The one I have used most recently for PHP projects is Pusher, but searching for 'PHP websockets' turns up plenty of libraries and code samples you could use.



Only top voted, non community-wiki answers of a minimum length are eligible